Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  8] [ 7]  / answers: 1 / hits: 5274  / 10 Years ago, fri, april 25, 2014, 12:00:00

I have here selectbox with option value USA and OTHERS. What I need is if I choose OTHERS on Selectbox1 the Selectbox2 should be display none and textbox1 comes out. Other problem also is it's name field, If I POST the value of name=cboState . How to remove the name of a field? Any help will appreciate.



<form action=try.php method=POST>
<select id=cboCountry>
<option value=USA>USA</option>
<option value=OTHERS>OTHERS</option>
</select>


Selectbox 2



<select id=cboState name=cboState>
<option value=Alabama>Alabama</option>
</select>


Textbox 1



<input type=text id=cboState name=cboState/>
<input type=submit>
</form>

More From » jquery

 Answers
5

Try this



HTML



<select id=cboCountry>
<option value=USA>USA</option>
<option value=OTHERS>OTHERS</option>
</select>

<select id=cboState name=cboState>
<option value=Alabama>Alabama</option>
</select>

<input type=text id=txtcboState name=cboState style=display:none;/>


JS



$(#cboCountry).change(function() { 

if ( $(this).val() == OTHERS) {

$(#cboState).hide();

$(#txtcboState).show();

}
else{

$(#cboState).show();
$(#txtcboState).hide();
}

});


Note: ID Must be unique for each element.



To remove The name attribute of input, you can use the following



$(#txtcboState).removeAttr('name');


DEMO HERE


[#45768] Thursday, April 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alekgermanb

Total Points: 616
Total Questions: 86
Total Answers: 105

Location: Aland Islands
Member since Thu, Dec 23, 2021
2 Years ago
;