Can't find asp:textbox in Javascript.

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-06-09T13:13:45Z Indexed on 2010/06/09 13:22 UTC
Read the original article Hit count: 182

Filed under:
|
|
|

I am trying to add the onkeydown attribute to an asp:textbox. For some reason my code can't find the textbox that is inside a loginview.

Am I doing something wrong?

<script type="text/javascript">
window.onload = function() {
    UserName.Attributes.Add("onKeyDown", "KeyDownHandler('" + btn.ClientID + "')");
    Password.Attributes.Add("onKeyDown", "KeyDownHandler('" + btn.ClientID + "')");
}

function KeyDownHandler(btn)
{
    if (event.keyCode == 13)
    {
        event.returnValue=false;    
        event.cancel = true;
        document.getElementById(btn).click();
    }
}
</script>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about textbox