I have a drop down menu in my html, and what I want is when the menu is changed, a JS function is called sending the selected value. What I have right now is this:
HTML/PHP:
<select name="selectSquad" class="SquadWeaponSelector" id="selectSquad" onchange="javascript:showWeaponEditorWindow(this.form.selectSquad);">
<?PHP
$max = $squadNumbers - 1;
$i = 0;
while($i <= $max){
echo "<option value=\"".$names_split[$i]."\"/>".$names_split[$i]."</option>";
$i++;
}
?>
</select>
JavaScript – what I want to happen:
function showWeaponEditorWindow(squad){
if(squad == "A PHP Value - Jack"){
alert("jack selected");
}
}
How would I achieve this?
try this,
you need to assign
squad.valuein your condition.Update:
you could use
selectedIndexto get the selected menu rember the the menu index starts at 0;so change
squad.valueto