I have page with several combo-boxes. The combo boxes options are populated with this PHP code. ($id and $label are collected from an ini file.)
<?echo'<select id="wbox" name="MPR">';
foreach($config[MPR] as $id=>$label){
switch ($id)
{
case ($id==select):
echo'<option value="0" selected="selected"></option>';
break;
case ($id>0 && $id<=10):
echo'<optgroup label="'.$label.'">';
break;
case ($id>10 && $id<=20):
echo'</optgroup>';
break;
default:
echo'<option value="'.$id.'">'.$label.'</option>';
}
}
echo'</select>';?>
At the end a submit button is clicked, and the values are handed off to another php script that redirects the user to a specific web page.
I would like to be able to direct the user to the selected page in an onclick event with the combo box. (Each option would be a new page, corresponding to the value assigned in the option.)
You said, "Each option would be a new page, corresponding to the value assigned in the option."
So, I assumed that you have something like
<select id="wbox" name="MPR">
<option value="0" selected="selected"></option>
<option value="http://yahoo.com">Yahoo</option>
<option value="http://stackoverflow.com">Stackoverflow/</option>
</select>
window.onload=function(){
var combo=document.getElementById('wbox');
combo.onchange=function(){
if(this.value!='0') window.open(this.value, '_blank');
};
};
Just put the above code inside your head
tags wrapped with script
tags like
<head>
<script type="text/javascript">
// above code goes here
</script>
</head>