I checked this forum for possible solutions, but none seem to work.
I have a text field and two submit buttons. The left button is "Cancel" and the right is "Submit". The default behavior is that the left button is selected when "Enter" is pressed. I'm trying to figure out a way to get the right button to be submitted.
Here's my test HTML:
<html><head><title>Test 7</title></head><body>
<script>
function test_onclick(obj) {
// when uncommented, and enter pressed - returns "buttonsub", but URL doesn't have parameter
// document.write('button clicked: ' + obj.name );
}
function enter()
{ if(window.event && window.event.keyCode == 13)
{
document.form1.buttonsub.click();
// return false; -- doesn't make any difference
// document.form1.submit(); // doesn't make any difference
}
return true; }
</script>
<form name="form1" action="focus_test_2.html" method="get">
Text 1: <input type="text" name="t1" value="s1" onkeypress="enter();"/>
<br>
<input type="submit" name="buttoncancel" value="cancel1" onClick="test_onclick(this);"/>
<input type="submit" name="buttonsub" value="submit1" onClick="test_onclick(this);"/>
</form>
</body></html>
If I press enter, then the passed URL is "/focus_test_2.html?t1=s1".
If I select the "Cancel" button, it's "focus_test_2.html?t1=s1&buttoncancel=cancel1".
If I select the "Submit" button, it's "focus_test_2.html?t1=s1&buttonsub=submit1".
I've tried every tip I've read about to get the second button to passed as a parameter when I press the enter key (i.e., I want the URL to be "focus_test_2.html?t1=s1&buttonsub=submit1"
What am I doing wrong?
I have a text field and two submit buttons. The left button is "Cancel" and the right is "Submit". The default behavior is that the left button is selected when "Enter" is pressed. I'm trying to figure out a way to get the right button to be submitted.
Here's my test HTML:
<html><head><title>Test 7</title></head><body>
<script>
function test_onclick(obj) {
// when uncommented, and enter pressed - returns "buttonsub", but URL doesn't have parameter
// document.write('button clicked: ' + obj.name );
}
function enter()
{ if(window.event && window.event.keyCode == 13)
{
document.form1.buttonsub.click();
// return false; -- doesn't make any difference
// document.form1.submit(); // doesn't make any difference
}
return true; }
</script>
<form name="form1" action="focus_test_2.html" method="get">
Text 1: <input type="text" name="t1" value="s1" onkeypress="enter();"/>
<br>
<input type="submit" name="buttoncancel" value="cancel1" onClick="test_onclick(this);"/>
<input type="submit" name="buttonsub" value="submit1" onClick="test_onclick(this);"/>
</form>
</body></html>
If I press enter, then the passed URL is "/focus_test_2.html?t1=s1".
If I select the "Cancel" button, it's "focus_test_2.html?t1=s1&buttoncancel=cancel1".
If I select the "Submit" button, it's "focus_test_2.html?t1=s1&buttonsub=submit1".
I've tried every tip I've read about to get the second button to passed as a parameter when I press the enter key (i.e., I want the URL to be "focus_test_2.html?t1=s1&buttonsub=submit1"
What am I doing wrong?