Submit form using the enter key i.e (if (event.keyCode==13))

Last post 05-06-2005, 6:55 AM by newboy. 0 replies.
Sort Posts: Previous Next
  •  11-09-2004, 4:52 PM 2353

    Submit form using the enter key i.e (if (event.keyCode==13))

    Hi,

     
    Would it be possible to submit the form i.e <form name="theForm" action="target.asp" method="post" ID="Form1"> when the user hits enter key
     
    I have written a js function already
     
    function checkEnter(event)
    {  
     var code = 0;
     
     if (NS4)
      code = event.which;
     else
      code = event.keyCode;
     if (code==13){
      event = null;
      document.form.submit();
        }   
    }
     
    My only problem and worry is, where would be a suitable place to call this function. I was hoping to use the onkeypress(). Does the CuteSoft textarea support this call??  Any suggestions would be great.  An example of what i'm trying to achieve is the similar to your asp.net chat . i.e the messages get posted/submitted when the enter key is struck.
     
    Regards Newboy
View as RSS news feed in XML