how to activate a textbox if I select an other option in drop down box

后端 未结 6 2017
滥情空心
滥情空心 2020-12-23 18:13

suppose I\'ve a 3 options in a drop down box say red , blue, others. If a user select option as an others then below a text box should be visible to wrtie his own favour

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 18:55

    This will submit the right form response (i.e. Select value most of the time, and Input value when the Select box is set to "others"). Uses jQuery:

      $("select[name="color"]").change(function(){
        new_value = $(this).val();
        if (new_value == "others") {
          $('input[name="color"]').show();      
        } else {
          $('input[name="color"]').val(new_value);
          $('input[name="color"]').hide();
        }
      });
    

提交回复
热议问题