Click here to Skip to main content
12,454,477 members (53,880 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
how to prevent auto submit of form when i press enter key on textbox?
Posted 21-Sep-10 0:11am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

<html>
<head>
<title>new document</title>
<script language="javascript" type="text/javascript">
<!--function goNext(the_val, field_name)
{    
if (the_val.length == 3) 
{        
document.forms['the_form'].elements[field_name].focus();    
}
}
-->
</script>
</head>
<body>
<form name="the_form">
<input type="text" name="tb1" onkeyup="goNext(this.value, 'tb2');"><br>
<input type="text" name="tb2" onkeyup="goNext(this.value, 'tb3');"><br>
<input type="text" name="tb3" onkeyup="goNext(this.value, 'tb4');"><br><input type="text" name="tb4" onkeyup="goNext(this.value, 'submit1');"><br>
<input type="submit" name="submit1" value="this is the submit button">
</form>
</body>
</html>
  Permalink  
v2
Comments
usankardurai 21-Sep-10 7:48am
   
Thank U for U R Reply.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

<script type="text/javascript">
    function disableSubmitOnEnter(event) {
        if (!event)
            event = window.event
        var keycode;
        if (event.which)
            keycode = event.which
        else
            var keycode = event.keyCode
        if (keycode == 13)
            return false;
        else return true;
    }
</script>

<input type="text" onkeydown="return disableSubmitOnEnter(event);" />
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

<script type="text/jscript" language="javascript">
    function submitButton() {
        if (window.event.keyCode == 0) {
            return false;
        }
        else {
            return true;
        }
    }
</script>

your button should like this:
<form id="form1" runat="server" onsubmit="return submitButton()">

If this is correct then Marked as Answer.
  Permalink  
v2
Comments
usankardurai 21-Sep-10 6:56am
   
<script language ="javascript" type ="text/javascript" >
function FocusNext(cid)
{
var i=document.getElementById (cid.id).getAttribute ('tabindex');
var iKeyCode = 0;
if (window.event)
iKeyCode = window.event.keyCode
else if (e)
iKeyCode = e.which;
if (iKeyCode == 13)
{
var ctrl=document.all;
for(var count = 0; ctrl.length ; count ++)
{
if(ctrl[count].tabIndex == i+1)
{
ctrl[count].focus();
}
}
}
else
return true;
}
</script>


i have three textbox in my page ,when i press enter key on textbox the next textbox focussed ,so its working properly but i add button control on page means it wont work, how to solve it?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100