How can I change drop down box #2 based on input from drop down box #1?

前端 未结 4 862
闹比i
闹比i 2021-01-14 17:41

I have two drop down menus.

<
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 18:01

    Assuming your dropdowns are dynamically built, I'd have your server generate a little javascript for you - the PHP code can map them, so the output looks something like:

    var _languageMap = {
        { 1: 12 },
        { 2: 11 },
        ...
        { 8: 14 }
    };
    

    Then set an eventhandler on change of your first dropdown, and set the second by looking up the value from your language map. If you're using jQuery, try something like:

    jQuery("#asset_id").change(function() {
        var trailerId = jQuery(this).val();
        var languageId = _languageMap[trailerId];
        jQuery("#country_id").val(languageId);
    });
    

    If you're not using jQuery, you can do the same with regular javascript - you'll just need to look up event handlers for dropdown lists - I just don't remember how to do that the old-fashioned way.

提交回复
热议问题