Click here to Skip to main content
15,611,312 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The javascript used for executing the submit button when enter button press after filling the textbox field. but it is not working properly...What will be my mistake...plz help me to find it.
<asp:TextBox ID="txtComment" runat="server" MaxLength="300"   onKeyPress="return processKey(event) ">
<script type="text/javascript">
      function processKey(e) {
      var key;
      if (window.event)
          key = window.event.keyCode;
          key = e.which;

      if (key == 13) {

          var btn = document.getElementById('ctl00_btnsend');

          if (btn != null) {


              event.keyCode = 0
Updated 17-Feb-13 20:32pm

Call js function like this onBlur="functionName(event)" you can also use onChange="functionName"
Share this answer
Member 9492907 18-Feb-13 3:34am    
not working these functions
Asim Mahmood 18-Feb-13 3:37am    
am currently using it
<asp:TextBox ID="TextBox1" runat="server" onChange="GetValues();" />
Your code seems fine. Have you added following attributes to your textbox?
                   "processKey('" + btnSearch.ClientID + "',event)"); //txtbox1 is an example, rename it your textbox name.

Also have a look at this link, same function in javascript has been written as the one you are using:

Capturing the Enter key to cause a button click[^]

Try this link as well:
Share this answer
Here simple Jquery code to do the same...

<script type="text/javascript">
        if (e.which == 13){
            // do your custom processing here

txtwhichpart is text box id
bsubmit_blist is button id

//code behind
protected void btnsearchhome_Click(object sender, EventArgs e)
   // here your code behind function of button
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900