Monday, June 6, 2011

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS,jQuery

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS.


Download latest jQuery and apply listed below code in your web page.


<script language="javascript" src="../js/jquery-1.6.js" type="text/javascript"></script>
<input type="text" name="t1" id="t1" onkeyup="javascript: if(setFocusNext(event)) $('#t2').focus();" />
<br/>
<input type="text" name="t2" id="t2" onkeyup="javascript: if(setFocusNext(event)) $('#t3').focus();" />
<br/>
<input type="text" name="t3" id="t3" />
<script type="text/javascript">
    function setFocusNext(e){
    var cd=0;
    if(window.event) {
        cd = e.keyCode;
    } else if(e.which) {
        cd = e.which;
    }
    if(cd==13) {
        return true;
    } else {
        return false;
    }
}
</script>

No comments:

Post a Comment