Reputation: 63
I have a table with id 'tbl' which contains textbox controls with id's like below
<table id="tbl">
txt1Text1
txt1Text2
txt2Text1
txt2Text2
txt3Text1
txt3Text2
.................
.................
I want to set the specif value in the textboxes that have id ends with Text1
I want to do it using jquery/javascript.
Thanks for help.
Upvotes: 3
Views: 1892
Reputation: 37660
You should add a fake css class, that allows you to "tag" the textboxes, then use jQuery to find these textbox using the css class selector.
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt1" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt2" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt3" />
<script type="text/javascript">
$(function(){
$(".FakeClass").val("42");
});
</script>
What is important here, is that the "FakeClass" does not have to exists. It's only a marker.
Upvotes: 1
Reputation: 68400
Try with this
$('#tbl input[id$="Text1"]').val('my value');
Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.
Upvotes: 0
Reputation: 144669
You can use Attribute Ends With
selector.
$('#tbl input[type=text][id$=Text1]').val('new value')
Upvotes: 5