Solved

Script Running Without Being Called

Posted on 2013-01-19
5
209 Views
Last Modified: 2013-01-19
I have two variables that I use for two switches in the header of my web page.  The problem is, when I run the script the alerts come up for both switches, the alerts are both correct but the second one should not run until it's called, which is on the onChange property of a dropdown...

<select name="Doggie" id="Doggie" onChange='javascript: getKitty();'>

Open in new window


The script that sets the var...
$(document).ready(function() {
	$("input:image").click(function(evt) {
	evt.preventDefault();
	var n = setSearch( $(this).val() )
	var m = getKitty( $(this).val() );})
	})

Open in new window


and the Script thats running when not called!
function getKitty(m)
{
	switch(m)
	{
		case "Place":
		alert("Place On Miss Kitty");
		break;
		case "Cuisine":
		alert("Cuisine On Miss Kitty");
		break;
}
}

Open in new window

0
Comment
Question by:DS928
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38797277
please provide a link to your page
0
 

Author Comment

by:DS928
ID: 38797283
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38797595
replace :
<select name="Doggie" id="Doggie" onChange='javascript: getKitty();'>
by :
<select name="Doggie" id="Doggie">

and use :
$(document).ready(function() {
	$("input:image").click(function(evt) {
  	    evt.preventDefault();
	    var n = setSearch( $(this).val() )
	    var m = getKitty( $(this).val() );
        })
        $("#Doggie").change(function() { getKitty(m); })
})

Open in new window

0
 

Author Comment

by:DS928
ID: 38797614
Perfect!  Thank you!
0
 

Author Closing Comment

by:DS928
ID: 38797617
Quick, Clean and Simple!  Thank You.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
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)
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…

776 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