Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Do alert on select

Hi experts, I wish to have an alert in every time  i do select. As the code shown below.. Thanks!

<!DOCTYPE html>
<html>
<body>

<form>
  <select name="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat" selected>Fiat</option>
    <option value="audi">Audi</option>
  </select>
</form>

<script>
function iSelect()
  {
    alert is here...
  }
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Hi Mukesh, I tried solution below base on what you suggested, but when i select one , example Volvo, It doesn't appear its value in the alert

<form>
  <select name="cars" onchange="iSelect(this)";>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat" selected>Fiat</option>
    <option value="audi">Audi</option>
  </select>
</form>

<script>
function iSelect(x)
  {
    alert(x)
  }
</script>
I change the  alert(x) to alert(x.value) and now its working. Thank you!
You're welcome!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot both of you guys!