Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

734 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