Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
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…

687 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