?
Solved

Script Running Without Being Called

Posted on 2013-01-19
5
Medium Priority
?
239 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 83

Expert Comment

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

Author Comment

by:DS928
ID: 38797283
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

840 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