在Javascript的dataList中获取TextBox的引用 [英] Get reference of TextBox inside dataList in Javascript
本文介绍了在Javascript的dataList中获取TextBox的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
结构像这样,
当我们单击立即预订"按钮时,objDiv可见.我想在a()javascript函数中获取txtSeatNo texbox的引用.
structure is somithing like this,
objDiv gets visible when we click on Book Now button i want to get reference of txtSeatNo texbox in aa() which is a javascript function.
I tried much and went through many of forum but no use, can any one help me
<asp:DataList ID="dlObject" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblCompanyName" runat="server" Text='<%#Eval("CompanyName") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblBusType" runat="server" Text='<%#Eval("ArrangementName") %>'></asp:Label>
</td>
<td>
<asp:Button ID="btnBookNow" runat="server" Text="Book Now" />
</td>
</tr>
<tr>
<td colspan="3">
<div visible="false" id="objDiv" runat="server">
<table>
<tr>
<td>
<img src="Images/somepic.gif" onclick="aa()" />
</td>
<td>
Seat No
</td>
<td>
<asp:TextBox ID="txtSeatNo" runat="server" CssClass="hideBorder" onKeyPress="return false"></asp:TextBox>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<script>
function aa()
{
var objSeatNo = <pre lang="xml">document.getElementById('<%=txtSeatNo.ClientID %>');
objSeatNo
}
</script></pre>.value = "5";
推荐答案
hi 试试这个
hi try this
var objSeatNo = <pre lang="xml">document.getElementById('<%=txtSeatNo.ClientID %>');
将上面的行更改为
change the above line to
var objSeatNo = document.getElementById("txtSeatNo").val();
您可以将txtSeatNo的值获取为ObjSeatNo.
you can get the value of txtSeatNo to ObjSeatNo.
indx是我保存在标签上的数据列表的选定索引号
indx is the selected index no of datalist which i saved on a lable
var clienttype = document.getElementById('<%=lblDivlastIndx_Itm.ClientID %>').value;
var indx = parseInt(clienttype);
indx=indx+1;
(#ctl00_ContentPlaceHolder1_dlRouts_ctl0" + indx +"_ txtSeatNo").val(新值");
现在可以正常使用了.
("#ctl00_ContentPlaceHolder1_dlRouts_ctl0"+indx+"_txtSeatNo").val(''New Value'');
Now its working fine.
这篇关于在Javascript的dataList中获取TextBox的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文