Reputation: 31
I have limited JavaScript knowledge and am trying to change a form so it autochanges when the drop down is selected without having to click a go button.
How would I amend the following code? There are 3 separate drop downs in there. I've tried inserting onselect
in there but it didnt seem to work?
<select name="season">
<option value="0"><?= $txt_all ?></option>
<?php
while($data = mysql_fetch_array($get_seasons))
{
if($data['SeasonID'] == $defaultseasonid)
echo "<option value=\"$data[SeasonID]\" SELECTED>$data[SeasonName]</option>\n";
else
echo "<option value=\"$data[SeasonID]\">$data[SeasonName]</option>\n";
}
mysql_free_result($get_seasons);
?>
</select>
<select name="matchtype">
<option value="0"><?= $txt_all ?></option>
<?php
while($data = mysql_fetch_array($get_types))
{
if($data['MatchTypeID'] == $defaultmatchtypeid)
echo "<option value=\"$data[MatchTypeID]\" SELECTED>$data[MatchTypeName]</option>\n";
else
echo "<option value=\"$data[MatchTypeID]\">$data[MatchTypeName]</option>\n";
}
mysql_free_result($get_types);
?>
</select> <input type="submit" name="submit" value="Go"><td bgcolor="<?php echo $inside_c ?>" align="center">
Other Stats <br><select name="changeto">
<option value="1"><?= $txt_match_statistics ?></option>
<option value="2"><?= $txt_recordbook ?></option>
<option value="5"><?= $txt_opponent_list ?></option>
<option value="6"><?= $txt_this_day ?></option>
</select> <input type="submit" name="changepage" value="Go">
Upvotes: 3
Views: 1616
Reputation: 36
With jQuery you can listen your drop down list when it changes.
$('select').change(function(){
// Do stuff
});
If you want to submit your form immediately after changing drop down value you can do this:
$('select').change(function(){
$('form').submit();
});
In right context you can see example from here(and mess around with it!): http://jsfiddle.net/EB635/
Upvotes: 1