Wednesday, 15 January 2014

jquery Option Function Should Work Separately -



jquery Option Function Should Work Separately -

i've written jquery function , want work separately.

$(function(){ $('.otherreason').hide(); $('.inqpurpose').change(function() { if($(this).find('option:selected').val() == "other"){ $('.otherreason').show(); }else{ $('.otherreason').hide(); } }); });

this html code repeat 4 times in form tag , when click other alternative field html work , want work separately

<select class="inqpurpose formfield" name="how2" id="how2"> <option>sales</option> <option>services</option> <option>corporate partnership</option> <option>corporate trade show</option> <option>requesting product samples trade show or event</option> <option>website feedback</option> <option value="other">other (please specify)</option> </select> <input class="formfield otherreason" type="text" placeholder="other reason" size="53" maxlength="300" />

if have other reason right after select alternative can utilize .nextall() , find first otherreason class

$(function(){ $('.otherreason').hide(); $('.inqpurpose').change(function() { if($(this).val() == "other"){ $(this).nextall('.otherreason:first').show(); }else{ $(this).nextall('.otherreason:first').hide(); } }); });

fiddle demo here http://jsfiddle.net/kgpay/1/

jquery

No comments:

Post a Comment