I just changed input button type from submit to button. Then it is working
as your need. The submit button will always call the form submit when ever
it is clicked, even when you press enter also it call the form submit. But
normal button do not call form submit all the time.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
   <head>
       <title>Test</title>
       <script language="javascript" type="text/javascript"
src="jquery-1.2.6.js"></script>
       <script language="javascript" type="text/javascript">
         $(function() {
           $(":text").keypress(function(e) {
             if (e.which == 13) {
               e.preventDefault();
             }
           });
           $("#txt").keypress(function(e) {
             if (e.which == 13) {
               $("#btn").click();
             }
           });
           $("#btn").click(function(e) {
             e.preventDefault();
             alert("Button clicked");
           });
         });
       </script>
   </head>
   <body>
     <form method="post" action="test.html">
       <div>
         <input id="txt" type="text" />
         <input id="btn" type="button" value="Submit" />
       </div>
     </form>
   </body>
</html>


On Mon, Nov 3, 2008 at 7:17 AM, Hullah <[EMAIL PROTECTED]> wrote:

>
> Ok, I see what you're saying now.  But stopPropigation doesn't work in
> this case either.  Looking at the code sample that I posted at the
> beginning, even if I add a e.stopPropagation() after the
> preventDefault() it still causes the form to submit.

Reply via email to