View Full Version : send forms
d-machine
01-21-2011, 07:26 AM
I've created a simple form:
<form>
<input type="text" id="teken" name="teken" value="" />
<br /><br />
<input type="button" value="send" onclick="check()" />
</form>
I don't use the submit button in order to use a js function, that works on the current page.
However, it's pretty annoying, after I write in the input text, and I press ENTER (on the keyboard) it doesn't send me the form..
What can I do?
djr33
01-21-2011, 07:36 AM
Replace the button with a regular submit input:
<input type="submit" value="send" />
And change your form tag to use the onsubmit event:
<form action="next.page.url" method="post_OR_get" onsubmit="check();">
Note that without specifying method and action in your form, your form isn't designed to do anything. Also be aware that javascript is optional and users can avoid it if they try or if they don't have javascript enabled. It will work most of the time, but it's not guaranteed or "secure".
d-machine
01-21-2011, 07:53 AM
I made it cause I don't won't to load a new page after sending the form,
I want to stay on the same page (without loading it again...).
How can I do it?
I want that everytime when you press ENTER it will run the check function.
I've tried to use: keypress event but I don't know how to apply it.
djr33
01-21-2011, 04:37 PM
Use the code I showed you above. If you want to block the page from reloading you can add return false; like this:
<form action="next.page.url" method="post_OR_get" onsubmit="check(); return false;">
That will NOT submit the form. However, it will execute the check() function and that can submit the form if needed.
Again, Javascript is unreliable, so if JS is disabled the form will submit when you press enter. There's no way to stop that.
d-machine
01-21-2011, 08:13 PM
Thank you very very much !! :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.