I am experiencing difficulty obtaining the id of a label control named tb_TA_2_6 within a form view using JavaScript.
I have attempted the following:
<script type ="text/jscript" language= "javascript" >
function autosum(t1, t2) {
var sum;
var a = document.getElementById('tb_TA_2_6'); // unable to retrieve id
var b = FindControl(FormView1, t2); // unsuccessful
var c = <%= 'tb_TA_2_6'.ClientID%>; // tb_TA_2_6 component unknown
var c = <%= tb_TA_2_6.ClientID%>; // tb_TA_2_6 does not exist in current context
var num2 = $(t2);
if (num2.textContent)
sum = num2.textContent;
else if (num2.innerText)
sum = num2.innerText;
else
sum = num2.innerHTML;
}
function FindControl(parentControl, strId)
{
var returnObject;
for(i=0;i < parentControl.elements.length; i++)
{
if(parentControl.elements[i].id.indexOf(strId) >= 0)
returnObject = parentControl.elements[i];
else if(parentControl.elements[i].hasChildNodes())
returnObject = FindControl(parentControl.elements[i],strId);
if(returnObject != null)
{ //if object is found return
return returnObject;
}
}
return returnObject;
}
</script>
Unfortunately, none of the methods above seem to be successful. Does anyone have any insights into the issue with the label having the id tb_TA_2_6?
The structure of the form view is as follows:
<asp:FormView ID="FormView1" runat="server" ClientIDMode="Static">
<ItemTemplate>
<asp:Label ID="labelID" runat="server" Text='<%#Bind("ID") %>' Visible="false"></asp:Label>
<table id="table1">
<tr>
<td>
<span > Textbox1 </span>
</td>
<td>
<asp:TextBox ID="tb_TA_2_4" onBlur="Javascript:autosum(this, '<%= tb_TA_2_6.ClientID%>');" runat="server" Text='<%#Bind("question6i","{0:$#,#0.00}") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
<span>6. (iii) Total Value </span>
</td>
<td>
<asp:Label ID="tb_TA_2_6" runat="server" ReadOnly="true" Text='<%#Bind("question6iii", "{0:$#,#0.00}") %>' OnPreRender="FormView1_PreRender" ></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
The rendered HTML is as follows, with style information removed:
<tr>
<td style="vertical-align: middle; width: 697px; height: 15px; border-style: solid;
border-color: #6699cc; border-width: 1px; border-top: 1px solid #fff;">
<span style="font-family: MS Sans Serif; font-size: 14px; color: #000000">6. (iii) Total
Value of All Benefits For Payment of Utilities </span>
</td>
<td class="alignright" style="vertical-align: top; width: 157px; height: 15px; border-style: solid;
border-color: #6699cc; border-width: 1px; border-left: 1px solid #fff; border-top: 1px solid #fff;">
<span id="ctl00_cph_Main_FormView1_tb_TA_2_6" ReadOnly="true" style="font-size:12pt;">$60.00</span>
</td>
</tr>