最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Passing a textbox value to javascript on key up function - Stack Overflow

programmeradmin4浏览0评论

Here i have passed the text control to the java script function but i just want to pass the value of the text box to the java script function instead on onkeyup.

function Changed(textControl) {
    var _txtEmpName = document.getElementById('<%=txtEmpName.ClientID%>');

    var _EnteredString = _txtEmpName.value;

<asp:TextBox
        ID="txtEmpName" runat="server" onkeyup="javascript: Changed( this );"></asp:TextBox>

Here i have passed the text control to the java script function but i just want to pass the value of the text box to the java script function instead on onkeyup.

function Changed(textControl) {
    var _txtEmpName = document.getElementById('<%=txtEmpName.ClientID%>');

    var _EnteredString = _txtEmpName.value;

<asp:TextBox
        ID="txtEmpName" runat="server" onkeyup="javascript: Changed( this );"></asp:TextBox>
Share Improve this question edited Aug 24, 2012 at 15:21 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Aug 24, 2012 at 15:19 user1588242user1588242 352 silver badges10 bronze badges 2
  • document.getElementById('<%=txtEmpName.ClientID%>').value ? – Joe Commented Aug 24, 2012 at 15:30
  • See this url it's working nice for me... [How to call javascript function on keyup event for asp:TextBox][1] [1]: stackoverflow./questions/5607313/… – csharpbd Commented Jul 14, 2013 at 18:06
Add a ment  | 

3 Answers 3

Reset to default 3

If you want to pass the value instead, simply do:

<asp:TextBox ID="txtEmpName" runat="server" 
 onkeyup="javascript: Changed( this.value );"></asp:TextBox>

Not sure if I understand, but if you want to pass the value you should use this.value instead of just this

<asp:TextBox ID="txtEmpName" runat="server" onkeyup="Changed(this.value)">
</asp:TextBox>

Maybe use onblur instead of onkeyup? You will be calling that function with every keystroke, is that something you really want to do?

发布评论

评论列表(0)

  1. 暂无评论