Solved

Script Running Without Being Called

Posted on 2013-01-19
5
229 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
[X]
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
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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

732 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