...

View Full Version : newbie question- form gets submitted twice



davidgr
09-27-2004, 08:03 PM
Hello I have written the following HTML page:


<html>
<body>
<form name="search" method="get" action="b.php">
<input type="text" name="query" id="query" onkeydown="if (window.event.keyCode == 13) { this.form.submit(); }" value=""></input>
</form>
</body>
</html>

sometimes when I press 'Enter' in the textfield, the target page b.php gets called twice.
Does anyone know what is causing it?
sometimes, it gets called only once.

I would appreciate any help in explaining what I am doing wrong

liorean
09-27-2004, 08:24 PM
Well, it's pretty easy to explain: The enter key usually triggers form submission purely by HTML means. So it does this time as well, since you don't cancel out the default handling. However, you at the same time use the event to - by script - perform form submission, which means that you submit it twice. The fix is to return false in the event handler.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum