jquery - Best way to form submission without using form action in JavaScript -
i building phonegap application using javascript, html , jquery mobile.
all html in same file, separated <div data-role="page">
pages.
several pages have form including 1 or more text/selection input , submit button.
the submit not traditional form submit button button using onclick runs javascript function can many things.
i want form have features:
- when pressing button , after running function, clear form.
- in cases function should change page.
- the enter button on 1 of inputs should submit form (activate function).
should use form html tag? if should use action? how clear form? etc.
if trying bind onclick input type="submit" you're gonna have bad time.
unfortunately if return false or e.preventdefault when clicking button, form still sends submit trigger once onclick code finished submit.
example:
<form action="woot.php" method="post"> <input type="submit" value="submit" onclick="alert('you clicked me! how you?! it's cool form still go woot.php. return false wont either.'); return false;"> </form>
what want do:
<form action="woot.php" method="post"> <input type="submit" value="submit" onsubmit="alert('you aint goin nowhere!'); return false;"> </form>
what should do:
<form action="woot.php" method="post"> <input type="button" value="button" onclick="alert('away you!'); window.location = 'http://www.google.com/';"> <input type="button" value="button" onclick="somecoolfunction();"> </form>
Comments
Post a Comment