Reputation: 633
I have a textbox inside a div tag which is placed inside a gridview
.
Below is the code :
<asp:TemplateField HeaderText="Color">
<ItemTemplate>
<div id="preview" style="width:100%; float:right">
<asp:TextBox ID="TB_color" runat="server" Width="50%" ReadOnly="true"></asp:TextBox>
</div>
<ajaxToolkit:ColorPickerExtender ID="ColorPickerExtender1" runat="server" targetcontrolid="TB_color" samplecontrolid="preview" PopupPosition ="Right" OnClientColorSelectionChanged="colorChanged" />
</ItemTemplate>
</asp:TemplateField>
How to read (or loop through) the TextBox TB_color
value in javascript?
Upvotes: 0
Views: 326
Reputation: 148180
You can find ids that contains with TB_color
to find all textboxes as asp.net generate ids that contains TB_color
for(i=0;i<document.forms[0].length;i++)
{
e=document.forms[0].elements[i];
if (e.id.indexOf("TB_color") != -1 )
{
console.log(e.id);
}
}
If you can use jQuery then it will be very simple.
$('[id*=TB_color]').each(function(){
console.log(this.id);
});
You may look more about jquery [Attribute Contains Selector [name*=”value”]] or Attribute Starts With Selector [name^=”value”]
Upvotes: 1
Reputation: 127
What are you really trying to accomplish? Maybe iterating through the textfields is not the best option.
You can try setting the ClientIDMode to predictable
, that way the ID of your text fields on html will be something like gridId_rowId_preview_TB_color.
If you want to do something to all of the TB_color text fields, you can set some class to the item template, and get all the elements that have that class.
Upvotes: 0