Reputation: 17321
i want to use onChange()
in select
but all of this commands not work for me:
HTML
<form method="post" name='testBank' id="testBank" enctype="multipart/form-data">
<select name="major_id" id='major_id' onchange="this.submit();">
<option value="">---</option>
<?
$query = mysql_query("select * from at_majors where view='1'");
while($row=mysql_fetch_assoc($query)){
?><option value="<? echo $row['major_id']?>" > TEST </option><?
}
?>
</select>
</form>
commands
onchange="this.submit()"
onchange="testBank.submit();"
onchange="this.testBank.submit()"
onchange="submit()"
onchange="document.all.submit()"
onchange="document.testBank.submit();"
i get this error:
this.submit is not a function
important
i dont like to use jquery or javascript for this method. please help me to repair this problem. thanks
Upvotes: 0
Views: 5741
Reputation: 96
If the submit input element have name as "submit" the form won't submit. So please remove the submit.
Avoid this
<input type="submit" name="submit" value="submit">
Use This
<input type="submit" name="xxx" value="xxx">
Upvotes: 1
Reputation: 9359
So here's your form (simplified a bit for the purposes of the demo):
<form name='testBank'>
<select name="major_id" onchange="submitTestBank();">
<option value="">---</option>
<option value="a">a</option>
<option value="b">b</option>
</select>
</form>
And then the most simple JavaScript (referring to the form by its name):
function submitTestBank() {
document.forms.testBank.submit();
}
Of course you could just add document.forms.testBank.submit();
directly to the onchange
attribute. Having a separate function like submitTestBank
is more reusable though. It helps if you want to attach a submit handler to multiple select
or input
elements.
Upvotes: 1
Reputation: 22174
That's because you are trying to submit the select
tag, not the form.
<form method="post" name='testBank' id="testBank" enctype="multipart/form-data">
<select name="major_id" id='major_id' onchange="document.getElementById('testBank').submit();">
This should work.
This should also work:
<select name="major_id" id='major_id' onchange="this.form.submit();">
Upvotes: 2
Reputation: 27
try this
<select name="major_id" id='major_id' onchange=this.form.submit();">
Upvotes: 1
Reputation: 5951
You do not like to use jQuery, then try this:
<select name="major_id" id='major_id' onchange="doSomething(this)">
Make sur to define your javascript before the select element:
function doSomething(sel) {
alert(sel.options[sel.selectedIndex].value);
}
Upvotes: 0