Solved

JavaScript dropdown onchange event

Posted on 2013-06-26
2
435 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

790 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