javascript - Why can I not select both input elements? -


this question has answer here:

i'm trying set value input element(s) match id.

but jquery.each picking first/one input element.

i'm trying perform ajax post , need both these id have same value.

html

@html.hiddenfor(u => u.transid)    //<input id="transid" name="transid" type="hidden" value="0">  @html.dropdownlistfor(u => u.transid, model.transmodes) //<input id="transid" name="transid" value="0"> 

script

$("#transid").each(function () {     $(this).val("2")     alert($(this).val());  }); 

cheers

an id must unique in html. if want name several elements same use class instead.

<input class="transid" name="transid1" type="hidden" value="0">  <input class="transid" name="transid2" value="0"> 

script

$(".transid").each(function () {     $(this).val("2")     alert($(this).val());  }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -