Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Script Running Without Being Called

Posted on 2013-01-19
5
217 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

839 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