index.php
<script type="text/javascript">
function setActionStar(btnValue) {
var actionstar = document.getElementById('actionstars');
alert(btnValue);
alert(actionstar.value);
actionstar.value = btnValue;
return false;
}
</script>
<form>
<?php
$actionstars = array("Jean Claude Van Damme", "Scott Adkins", "Dolph Lundgren", "Michael Jai White");
$ctr = 1;
?>
<select id="actionstars" name="actionstars">
<?php
foreach($actionstars as $as){
echo "<option value=" . $ctr . " >" . $as . "</option>";
$ctr++;
}
?>
</select>
<br />
<?php
for($i=1; $i<= count($actionstars); $i++) {
?>
<input type="submit" value="<?php echo $i; ?>" onclick="setActionStar(this.value);" />
<?php
}
?>
</form>
I've been dealing with this dilemma for almost 2 hours. I don't know what's wrong with this. What I'm trying to do is whenever the user clicks a button, it will change the combobox value to the value of the button. For example, if I hit button 1, the combobox will have the value 1. It's working with other HTML elements but I don't know why it's not applicable here.
I am very new to programming so don't be harsh to me. Please don't think I didn't do an effort on this. It's just I don't know what I am doing honestly. Please help.