admin管理员组文章数量:1425161
On my page, I'm using textbox with calendar extender to get the date value.
I've added onchange="ValidateStartDate();"
to the textbox.
<asp:TextBox ID="TextBoxStartDate" runat="server" ForeColor="Red"
onchange="ValidateRsmStartDate();">
</asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderStartDate"
TargetControlID="TextBoxStartDate"
BehaviorID="ceStartDate"
PopupButtonID="CalendarExtenderStartDatePopup"
Format="MM/dd/yyyy" runat="server">
</asp:CalendarExtender>
<img class="Spacer" id="CalendarExtenderStartDatePopup" src="Images/Calendar.png"
alt="Start Date" />
My javascript function:
function ValidateStartDate() {
var txtDate = document.getElementById('<%=TextBoxStartDate.ClientID %>');
alert(txtDate.innerHTML);
}
But on alert()
, I get no value at all.
On my page, I'm using textbox with calendar extender to get the date value.
I've added onchange="ValidateStartDate();"
to the textbox.
<asp:TextBox ID="TextBoxStartDate" runat="server" ForeColor="Red"
onchange="ValidateRsmStartDate();">
</asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderStartDate"
TargetControlID="TextBoxStartDate"
BehaviorID="ceStartDate"
PopupButtonID="CalendarExtenderStartDatePopup"
Format="MM/dd/yyyy" runat="server">
</asp:CalendarExtender>
<img class="Spacer" id="CalendarExtenderStartDatePopup" src="Images/Calendar.png"
alt="Start Date" />
My javascript function:
function ValidateStartDate() {
var txtDate = document.getElementById('<%=TextBoxStartDate.ClientID %>');
alert(txtDate.innerHTML);
}
But on alert()
, I get no value at all.
3 Answers
Reset to default 3Textbox does not
have innerHTML
, you need to use value
Change
alert(txtDate.innerHTML);
To
alert(txtDate.value);
You can easily integrate it from jquery. Just write below line in your function.
alert($("#<%=TextBoxStartDate.ClientID %>").val());
Or
Replace your code from alert(txtDate.innerHTML);
to alert(txtDate.value);
Using jQuery:
$(function(){
$('<%=TextBoxStartDate.ClientID%>').on("change", function(){
alert($(this).val());
});
});
本文标签: aspnetGetting textbox value in javascript code after onchangeStack Overflow
版权声明:本文标题:asp.net - Getting textbox value in javascript code after onchange - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700801a2620550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论