Solved

code does not work inside $(document).ready(function() {

Posted on 2012-03-24
2
288 Views
Last Modified: 2012-03-24
can some one tell me why may code does not work when I put it inside $(document).ready(function() { });
it works fine if I do not put it in there.

// JavaScript Document
<!--
$(document).ready(function() { ////makes sure document is ready before excuting any jquery  
/*--------------------------------------------------------------------------------------*/
function bizType(type)
        {
        if(type=='MEDI') {
			$("#medical_type_box").show();
			$("#profile_1_box").hide();
			$("#profile_1").val("");  
            $("#profile_2_box").hide();
			$("#profile_2").val("");
			$("#restaurant_type_box").hide();
			$("#restaurant_type").val("");
		    }
		
		if(type=='REST') {
			$("#restaurant_type_box").show();
			$("#profile_1_box").hide();
			$("#profile_1").val("");
            $("#profile_2_box").hide();
			$("#profile_2").val("");
			$("#medical_type_box").hide();
			$("#medical_type").val("");
		    }
			
		if(!(type=='MEDI' || type=='REST')) {
			$("#profile_1_box").show();
			$("#profile_2_box").show();
			$("#restaurant_type_box").hide();
			$("#restaurant_type").val("");
			$("#medical_type_box").hide();
			$("#medical_type").val("");
		    }
         }

/*--------------------------------------------------------------------------------------*/
}); //// end of document ready
///End jquery
/*--------------------------------------------------------------------------------------*/
-->

Open in new window

0
Comment
Question by:Luey
2 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37761644
that's because you are calling the function bizType somewhere else, and that somewhere else gets executed before $(document).ready.

You actually don't need it inside $(document).ready
That's a function. It will only execute when you call it.
What you need inside $(document).ready is stuff that needs to initialize and act upon the DOM, which only exists on $(document).ready.

PS: You can convert those 3 'if' s to if(...){---} else if(...) {---} else {---}
0
 

Author Closing Comment

by:Luey
ID: 37761655
ok now i understand thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

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

23 Experts available now in Live!

Get 1:1 Help Now