Solved

JavaScript dropdown onchange event

Posted on 2013-06-26
2
443 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 500 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

695 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