Submit form without using onSubmit() and 'return false;'
I've read thats the old wrong way of doing things. I'm not using jQuery either. This wont work though :confused:
Code:
<html>
<body>
<form name="contact" id="form_contact" action="" method="post">
<input type="text" name="form_text" id="form_text" value="">
<button type="submit" name="form_submit" id="form_submit" value="Go">Go</button>
</form>
<script>document.getElementById('form_contact').addEventListener('submit', bling, false);
function bling() {
alert('submitted');
stop_event('submit');
return false;//last resort, not really wanting to use this
}
function stop_event(ev) {
if (ev.stopPropagation) {
ev.stopPropagation();
}
else {
ev.cancelBubble = true;
}
if (ev.preventDefault) {
ev.preventDefault();
}
else {
ev.returnValue = false;
}
}</script>
</body>
</html>
http://jsfiddle.net/PG67k/