run js function with onchange event on selet option

I have a form with a select

<select name="students" muliple>
<option value="student1">Student1</option>
<option value="student2">Student2</option>
<option value="student3">Student3</option>
<option value="student4">Student4</option>
</select>

I need to run a js function when options are clicked, something like:

<select name="students" muliple>
<option value="student1" onClick="check(this);">Student1</option>
<option value="student2" onClick="check(this);">Student2</option>
<option value="student3" onClick="check(this);">Student3</option>
<option value="student4" onClick="check(this);">Student4</option>
</select>

I have it like that but it is not running the function

the check(this) function is

<script>
      
      function test()
      {
alert("I am an alert box!");
      }
</script>

I would need the alrt box to appear when the options are checkd/unchecked. It is not happening
robrodpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
http://jsfiddle.net/yo31wdh8/

<select name="students" muliple onChange="test(this);">
    <option value="student1">Student1</option>
    <option value="student2">Student2</option>
    <option value="student3">Student3</option>
    <option value="student4">Student4</option>
</select>

Open in new window

<script>
function test(el) {
    alert("I am an alert box!");
    alert(el.value)
}
</script>

Open in new window

0
leakim971PluritechnicianCommented:
you function have the wrong name : http://jsfiddle.net/m9jobs85/1/
it's check instead test.

work too : http://jsfiddle.net/5xhsnwh7/
0
robrodpAuthor Commented:
sorry the select does include the multiple option.
0
GaryCommented:
You cannot capture a click on the OPTION tag in IE, so your original code (even fixed) will not work that way

You can get an array of the selected values.

If you really do need to know which one was clicked then you would be better looking at checkboxes or using a LIst tag
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robrodpAuthor Commented:
Thx for pointing that out
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.