How can I iterate through each of these hidden fields and change each one's value with JQuery?
<asp:HiddenField ID="field1" runat="server"/>
<asp:HiddenField ID="field2" runat="server"/>
<asp:HiddenField ID="field3" runat="server"/>
How can I iterate through each of these hidden fields and change each one's value with JQuery?
<asp:HiddenField ID="field1" runat="server"/>
<asp:HiddenField ID="field2" runat="server"/>
<asp:HiddenField ID="field3" runat="server"/>
You can do it by combining :hidden
selector and attribute starts with
selector,
$(":hidden[id^=field]").val(function(_,val){
return "anyValueYouWant";
});
To make sure that the ID not change use also the ClientIDMode="Static"
on each control. The ID can change if you place that code on any page that use any master page, or is inside any custom control. So your control must be:
<asp:HiddenField ID="field1" runat="server" ClientIDMode="Static" />
<asp:HiddenField ID="field2" runat="server" ClientIDMode="Static" />
<asp:HiddenField ID="field3" runat="server" ClientIDMode="Static" />