Link to home
Create AccountLog 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
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks a lot both of you guys!