Trigger change event of dropdown

后端 未结 6 1029
逝去的感伤
逝去的感伤 2020-12-02 12:12

I want to trigger the change event of dropdown in $(document).ready using jquery.

I have a cascading dropdown for country and state in user details page. how can i s

6条回答
  •  攒了一身酷
    2020-12-02 12:38

    If you are trying to have linked drop downs, the best way to do it is to have a script that returns the a prebuilt select box and an AJAX call that requests it.

    Here is the documentation for jQuery's Ajax method if you need it.

    $(document).ready(function(){
    
        $('#countrylist').change(function(e){
            $this = $(e.target);
            $.ajax({
                type: "POST",
                url: "scriptname.asp", // Don't know asp/asp.net at all so you will have to do this bit
                data: { country: $this.val() },
                success:function(data){
                    $('#stateBoxHook').html(data);
                }
            });
        });
    
    });
    

    Then have a span around your state select box with the id of "stateBoxHook"

提交回复
热议问题