51 users online (1 members and 50 guests)  


  Results 1 to 2 of 2

Related

  1. Control panels.    Forum: Web Hosting Forum
    Replies: 6
  2. Your favorite control panel?    Forum: Web Hosting Forum
    Replies: 14
  3. Add control to Html Doc dynamically    Forum: Javascript Forum
    Replies: 0
  4. Control chart Y lable value    Forum: Graphics Forum
    Replies: 1
  1. #1
    kamii47's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2007
    Posts
    3

    onkeypress move to next control [except when the focus is on button control]

    I am working on asp.net 2.0.
    I want's a javascript function which i will put in the master page body section
    What I want's is that when ever a keypress is enter the focus will move to next control.
    Provided that if the focus is on button then i doesn't want this function to do any thing.

  2. #2
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Thumbs up Re: onkeypress move to next control [except when the focus is on button control]

    Call the follwing javascript function in the onKeyPress event of the needed fields with the event and the nextField's id....
    Code:
    <html>
    <body>
    <script type="text/javascript">
    function checkReturn(ret,nextFieldName)
    {
    var kcode
    var cChar
    var retCheck
    if(window.event) 
     {
     kcode = ret.keyCode
     }
    cChar= String.fromCharCode(kcode)
    retCheck= /\r/
    if(retCheck.test(cChar)){
    document.getElementById(nextFieldName).focus();
    }
    }
    </script>
     
    <form>
    Text1 : <input type="text" id="txt1" onkeypress="checkReturn(event,'txt2')" />
    Text2 : <input type="text" id="txt2">
    </form>
    </html>



Tags for this Thread