HLRosenberger
asked on
access controls within a repeater from javascript
How can I access controls within a repeater from javascript? I do not know jQuery, so I want to use straight javascript.
Please post your repeater code. Jquery is pretty simplye and easy if you know javascript. Once you know how to select basic elements, you will love it and never want to do traditional JS.
Give Same Name to ur elements in the repeater and get all with document.GetElementsByName function
http://w3schools.com/jsref/met_doc_getelementsbyname.asp
http://w3schools.com/jsref/met_doc_getelementsbyname.asp
ASKER
guru_sami -
I do want to learn jQuery. But, have idea how to use it. I know javascript.
see attached code. There are 3 rows in the repeater. I need to reference the "name" and "description" in javascript to do input validation.
AddTds-client-wishlist.htm
I do want to learn jQuery. But, have idea how to use it. I know javascript.
see attached code. There are 3 rows in the repeater. I need to reference the "name" and "description" in javascript to do input validation.
AddTds-client-wishlist.htm
ASKER
To use jQuery, do I need to install anything? Add some sort of directive in my page?
1: Yes you need to reference the jquery library in the head section of your page. You can use CDN or you can download the jquery js file/add it to your solution and reference it locally like any other .js file. The below one is referencing the script via microsoft CDN.
2: Here is sample script that will get the name inputs. The condition for below to work is it assumes you have set CssClass="name" for your name textboxes.
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js" type="text/javascript"></script>
2: Here is sample script that will get the name inputs. The condition for below to work is it assumes you have set CssClass="name" for your name textboxes.
<script type="text/javascript">
$(function () {
// alert($("input.name").length); //this will return the count of input elements that has css class=name
$("input.name").each(function () {
alert($(this).val());//output the value in each input that has class=name
});
});
</script>
did u check my comment about javascript ?
ASKER
non_zero - yes I did. But I cannot get it to work. I have used javascript in the past to do this, but I always encounter difficulties. And I am now.
I had attached the rendered HTML/asp. I'm now attaching the source . Can you tell me how to access the name and description text boxes within the repeater?
AddTds-client-wishlist.aspx
I had attached the rendered HTML/asp. I'm now attaching the source . Can you tell me how to access the name and description text boxes within the repeater?
AddTds-client-wishlist.aspx
change ur repeater code with this ..
and in ur javascriptcode
document.GetElementsByName ("name")[n ] gives the n th name
document.GetElementsByName ("descript ion")[n] gives the n th description
and in ur javascriptcode
document.GetElementsByName
document.GetElementsByName
><asp:Repeater runat="server" id="Tds_client_wishlist_giftTableControlRepeater"> <ITEMTEMPLATE> <Tabor:Tds_client_wishlist_giftTableControlRow runat="server" id="Tds_client_wishlist_giftTableControlRow">
<tr><td class="ticnb" scope="row">
<asp:ImageButton runat="server" id="Tds_client_wishlist_giftRowDeleteButton" causesvalidation="False" commandargument="DeleteOnUpdate" commandname="DeleteRecord" cssclass="button_link" imageurl="../Images/icon_delete.gif" tooltip="<%# GetResourceValue("Txt:DeleteRecord", "Tabor") %>">
</asp:ImageButton>
</td><td class="ttc" style="font-weight:bold;color:#408080;text-align:right;"><asp:label id="lblChoice" runat="server" text="First Choice" width="125px"></asp:label></td><td class="ttc requiredbefore" runat="server" id="gift_name"><span style="white-space:nowrap;">
<asp:TextBox runat="server" id="name" name ="name" Columns="50" MaxLength="50" cssclass="field_input" width="150px"></asp:TextBox>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="nameTextBoxMaxLengthValidator" ControlToValidate="name" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Name") %>"></BaseClasses:TextBoxMaxLengthValidator></span>
</td><td class="ttc requiredbefore" runat="server" id="gift_description"><span style="white-space:nowrap;">
<asp:TextBox runat="server" id="description" name="description" MaxLength="500" columns="60" cssclass="field_input" rows="3" textmode="MultiLine" width="230px"></asp:TextBox>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="descriptionTextBoxMaxLengthValidator" ControlToValidate="description" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Description") %>"></BaseClasses:TextBoxMaxLengthValidator></span>
</td><td class="ttc requiredbefore"><asp:dropdownlist cssclass="Filter_Input" id="ddQuantity" runat="server" /></td><td class="ttc"><span style="white-space:nowrap;">
<asp:TextBox runat="server" id="color" Columns="15" MaxLength="15" cssclass="field_input" width="75px"></asp:TextBox>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="colorTextBoxMaxLengthValidator" ControlToValidate="color" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Color") %>"></BaseClasses:TextBoxMaxLengthValidator></span>
</td><td class="ttc"><span style="white-space:nowrap;">
<asp:TextBox runat="server" id="size" Columns="15" MaxLength="15" cssclass="field_input" width="75px"></asp:TextBox>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="sizeTextBoxMaxLengthValidator" ControlToValidate="size" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Size") %>"></BaseClasses:TextBoxMaxLengthValidator></span>
</td><td class="ttc"><span style="white-space:nowrap;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-right: 5px; vertical-align:top">
<asp:TextBox runat="server" id="rank" Columns="14" MaxLength="14" cssclass="field_input" visible="False" width="0px"></asp:TextBox></td>
<td>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="rankTextBoxMaxLengthValidator" ControlToValidate="rank" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Rank") %>"></BaseClasses:TextBoxMaxLengthValidator></td>
</tr>
</table>
</span>
<span style="white-space:nowrap;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-right: 5px; vertical-align:top">
<asp:TextBox runat="server" id="request_date" Columns="20" MaxLength="20" cssclass="field_input" visible="False" width="0px"></asp:TextBox></td>
<td>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="request_dateTextBoxMaxLengthValidator" ControlToValidate="request_date" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Request Date") %>"></BaseClasses:TextBoxMaxLengthValidator></td>
</tr>
</table>
</span>
<span style="white-space:nowrap;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-right: 5px; vertical-align:top">
<asp:TextBox runat="server" id="quantity" Columns="14" MaxLength="14" cssclass="field_input" visible="False"></asp:TextBox></td>
<td>
<BaseClasses:TextBoxMaxLengthValidator runat="server" id="quantityTextBoxMaxLengthValidator" ControlToValidate="quantity" ErrorMessage="<%# GetResourceValue("Val:ValueTooLong", "Tabor").Replace("{FieldName}", "Quantity") %>"></BaseClasses:TextBoxMaxLengthValidator></td>
</tr>
</table>
</span>
</td></tr></Tabor:Tds_client_wishlist_giftTableControlRow>
</ITEMTEMPLATE>
</asp:Repeater>
Did you try the sample code in my last post?
ASKER
non_zero - I can't change the repeater code. I'm using Code Generation Product call Iron Speed. It's generating the pages. I need to work with what it generates.
guru_sami - I did not do anything with jQuery. I do not have the time to learn something new right now. I do want the learn jQuery, and appreciated your post.
guru_sami - I did not do anything with jQuery. I do not have the time to learn something new right now. I do want the learn jQuery, and appreciated your post.
ASKER
Nothing I try works. Any suggestions? I have a name and a description field within a repeater. All I want to do is input validation - if a name is entered without a description, or a description is entered with a name, for any row within the repeater.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.!