Add input-box when selecting a specific option into select drop down

后端 未结 3 1183
野的像风
野的像风 2021-01-14 13:02

i need to add input to a select option when it is selected. whenever the user selects \'other\' an input box is there for the user to enter in data.

html:

         


        
3条回答
  •  一生所求
    2021-01-14 13:42

    See it in action here.

    HTML:

    
    
    

    jQuery:

    $(document).ready(function() {
        $("#choose").on("change", function() {
            if ($(this).val() === "other") {
                $("#otherName").show();
            }
            else {
                $("#otherName").hide();
            }
        });
    });
    

    Note the value="other" attribute on the "Other" option. That's how the script determines if the "Other" option is selected.

    Hope this helps!

提交回复
热议问题