Forum Moderators: open

Message Too Old, No Replies

Javascript form submission using <select> menu

         

ish

9:29 am on May 13, 2007 (gmt 0)

10+ Year Member



Hi everyone.

I am trying to create a form that submits when the user makes a selection from a <select> menu. There will be no Submit button on the form. I've managed to get it working in Opera using the code below, but I am unable to get it working in Internet Explorer.

Thank you for any help you can offer.

---------------------------

function DoSubmission() {
document.MyForm.submit();
}

---------------------------

<form name="MyForm" action="blah.php" method="get">

---------------------------

<select name="vphselect">
<option value="1" onClick=\"DoSubmission();\">Option 1</option>
<option value="2" onClick=\"DoSubmission();\">Option 2</option>
<option value="3" onClick=\"DoSubmission();\">Option 3</option>
</select>

---------------------------

birdbrain

11:37 am on May 13, 2007 (gmt 0)



Hi there ish,

try it like this example...


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
var df;
window.onload=function() {
df=document.forms[0];
df[0].onchange=function(){
DoSubmission();
}
}
function DoSubmission() {
if(df[0].value!='') {
df.submit();
}
}
</script>

</head>
<body>

<form action="http://www.google.com" method="get">
<div>
<select name="vphselect">
<option value="">--options--</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
</form>

</body>
</html>

birdbrain

ish

10:55 am on May 14, 2007 (gmt 0)

10+ Year Member



Hi birdbrain

Thank you for your reply. I've tested the code, but unfortunately it only submits the form when you make a selection in the first instance of a <select> menu on any page. For some reason it just ignores 2nd and subsequent menus..

ish

11:01 am on May 14, 2007 (gmt 0)

10+ Year Member



Aha, I have found a solution. And a very easy one too :)

<select name='myfield' onchange='this.form.submit()'>
<option .... >
...
</select>
</form>

birdbrain

11:08 am on May 14, 2007 (gmt 0)



Hi there ish,

I am trying to create a form that submits when the user makes a selection from a <select> menu.

I assumed from that, that there would only be one select element and coded accordingly. ;)

birdbrain