Click here to Skip to main content
15,938,682 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to get the value of textbox in the templateview of a gridview. But the script i have is not working. My codes are below. Thanks

<asp:TemplateField HeaderText="ExamType">
<edititemtemplate>
<asp:DropDownList Width="80px" ID="txtExamType" onChange="check_grade()" MaxLength="20" runat="server">
<asp:ListItem Value=" " Selected="True">--Select
<asp:ListItem>SSCE
<asp:ListItem>WASSCE

<asp:RequiredFieldValidator ID="rfvtxtExamType" runat="server" ControlToValidate="txtExamType" Text="*" ForeColor="Red" ValidationGroup="validaiton" />

<itemtemplate>
<asp:Label ID="lblExamType" runat="server" Text='<%#Eval("ExamType") %>' />

<footertemplate>

<asp:DropDownList Width="80px" ID="txtftrExamType" onChange="check_grade1()" MaxLength="20" runat="server">
<asp:ListItem Value=" " Selected="True">--Select
<asp:ListItem>SSCE
<asp:ListItem>WASSCE

<asp:RequiredFieldValidator ID="rfvExamType" runat="server" ControlToValidate="txtftrExamType" Text="*" ForeColor="Red" ValidationGroup="validaiton" />




<script>
function check_grade() {
document.getElementById('<%# Container.FindControl("txtGrade").ClientID %>').innerHTML = "";
var ExamType = $('<%# Container.FindControl("txtExamType").ClientID %>').val();

};
</script>
Posted
Comments
F-ES Sitecore 14-Jan-16 11:28am    
Where is txtGrade defined?

Below will work

Change the below

ASP.NET
<asp:DropDownList Width="80px" ID="txtftrExamType" onChange="check_grade1()" MaxLength="20" runat="server">


To

ASP.NET
<asp:DropDownList Width="80px" ID="txtftrExamType" onChange="check_grade1('<%# Container.FindControl("txtGrade").ClientID %>','<%# Container.FindControl("txtExamType").ClientID %>' )" MaxLength="20" runat="server">


and change the below Java script


function check_grade() {
document.getElementById('&lt;%# Container.FindControl("txtGrade").ClientID %&gt;').innerHTML = "";
var ExamType = $('&lt;%# Container.FindControl("txtExamType").ClientID %&gt;').val();

};


TO

<script>
function check_grade(gradeTextBox, emailTypeTextBox) {
document.getElementById(gradeTextBox).innerHTML = "";
var ExamType = $(emailTypeTextBox).val();

};
</script>
 
Share this answer
 
For JavaScript, it's not "text box", it's an input element of the type "text". No matter, you just need to get the reference to an HTML element DOM object and use the property value. For example:
JavaScript
var myTextBox = document.getElementById("Your_text_box_id");
var text = myTextBox.value;


—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900