C
Chris
I am wondering about what seems to be a particular quirk in Javascript
that does not allow form event listeners (e.g. "onsubmit=...") to work
properly. In the code below, I would like to set up a function
(doOnSubmit) that is called when the form is submitted.
But there is a "return false;" in the "onclick" of the button. If this
"return false" is removed, the code works as I would hope it would.
With it there, doOnSubmit is never called.
<html>
<head>
<title>A Broken Umbrella</title>
<script language="Javascript">
function doOnClick() {
document.getElementById('form1').input.value = 'quietly';
}
function doOnSubmit(e) {
e.target.input.value = 'loudly';
alert('doOnSubmit(e) called.');
}
function startUp() {
document.getElementById('form1').onsubmit = doOnSubmit;
}
</script>
</head>
<body onload="startUp();">
<form id="form1" method="GET" action="somepage.html">
<input id="input" name="input" type="text" value="adverbs" /><br />
<button onclick="doOnClick(); this.submit; return
false;">Submit</button>
</form>
</body>
</html>
If I had the option to, I would remove the "return false" from the
button. However, I am unable to do so and would still like to be able
to modify the onsubmit event.
Thanks for any insight you may have.
that does not allow form event listeners (e.g. "onsubmit=...") to work
properly. In the code below, I would like to set up a function
(doOnSubmit) that is called when the form is submitted.
But there is a "return false;" in the "onclick" of the button. If this
"return false" is removed, the code works as I would hope it would.
With it there, doOnSubmit is never called.
<html>
<head>
<title>A Broken Umbrella</title>
<script language="Javascript">
function doOnClick() {
document.getElementById('form1').input.value = 'quietly';
}
function doOnSubmit(e) {
e.target.input.value = 'loudly';
alert('doOnSubmit(e) called.');
}
function startUp() {
document.getElementById('form1').onsubmit = doOnSubmit;
}
</script>
</head>
<body onload="startUp();">
<form id="form1" method="GET" action="somepage.html">
<input id="input" name="input" type="text" value="adverbs" /><br />
<button onclick="doOnClick(); this.submit; return
false;">Submit</button>
</form>
</body>
</html>
If I had the option to, I would remove the "return false" from the
button. However, I am unable to do so and would still like to be able
to modify the onsubmit event.
Thanks for any insight you may have.