Solved

JavaScript dropdown onchange event

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

733 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