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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -