?
Solved

JavaScript dropdown onchange event

Posted on 2013-06-26
2
Medium Priority
?
446 Views
Last Modified: 2013-06-27
hi,

I have 2 HTML dropdown menus and I am wondering how I can have 1 function to see what dropdown menu made the change to execute some code.  I know I can have 2 functions, 1 for each but I would like to do it in one

Thank you for all of your help in advance
0
Comment
Question by:thomasm1948
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 39279995
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function doSomethingWith(list)
{
	switch(list.name)
	{
		case 'list1':
			alert( 'Do whatever you need to do for list 1');
			break;
		case 'list2':
			alert( 'Do whatever you need to do for list 2');
			break;
		default:
			alert( 'Do whatever you need to do for any other list');
			break;
	}
}
</script>

</head>
<body>
<select name="list1" onchange="doSomethingWith(this)"><option value="a">a</option><option value="b">b</option></select>
<select name="list2" onchange="doSomethingWith(this)"><option value="a">a</option><option value="b">b</option></select>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:thomasm1948
ID: 39282035
Excellent that work perfectly.

Thank  You
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question