We help IT Professionals succeed at work.

run js function with onchange event on selet option

robrodp
robrodp asked
on
224 Views
Last Modified: 2014-08-14
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
Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
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

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

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

work too : http://jsfiddle.net/5xhsnwh7/
robrodpProgrammer

Author

Commented:
sorry the select does include the multiple option.
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
robrodpProgrammer

Author

Commented:
Thx for pointing that out
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.