Solved

Script Running Without Being Called

Posted on 2013-01-19
5
190 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
Comment Utility
please provide a link to your page
0
 

Author Comment

by:DS928
Comment Utility
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
Perfect!  Thank you!
0
 

Author Closing Comment

by:DS928
Comment Utility
Quick, Clean and Simple!  Thank You.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
(code works) but print excel in Landscape 5 49
radio button value 3 43
Website Home page blank 4 25
JavaScript Scope issue 4 15
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…
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.
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now