Solved

JavaScript dropdown onchange event

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now