Solved

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

Posted on 2012-03-24
2
291 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

860 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