Thu - Apr 05, 2007 : 12:43 pm
no mood
Javascript form submission gotcha
I spent about 2 hours today trying to debug something so stupid and simple as the following code.
<script>
function submit_me() {
document.form1test.submit();
}
</script>
<form name="form1test" method="post" action="newuser.php">
<input name="submit" type="button" value="save" onclick="submit_me()">
</form>
Doesn't that look like it should work? Heh... yeah... right... The stupid gotcha is the {name="submit"} on the button field. *that* makes it impossible to submit this form via JS. The correct code can be found below:
<script>
function submit_me() {
document.form1test.submit();
}
</script>
<form name="form1test" method="post" action="newuser.php">
<input type="button" value="save" onclick="submit_me()">
</form>
and that's that!
Computers / Programming