jquery - I want to wire a dropdown statement to have a different event fire for each selection made using a switch statement.

I want to wire a dropdown statement to have a different event fire for each selection made using a switch statement and have it show different dialogs for each statement made.. these dialogs will fire different controller actions.. Can someone please help me on doing this when the document loads?
cbruneAsked:
Who is Participating?
 
Chris StanyonCommented:
I guess you could bind the change event and 'switch' either the value or the text and call your functions from there

//html
<select id="myDropdown">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
</select>

//jQuery
$(document).ready(function() {
	$('#myDropdown').change(function() {

	switch($(this).val()){
		case '1':
			alert ("Number 1");
			break;
		case '2':
			alert ("Number 2");
			break;
		case '3':
			alert ("Number 3");
			break;
		default:
			alert ("Something else");
	}
	});
});

Open in new window

0
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.

All Courses

From novice to tech pro — start learning today.