?
Solved

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

Posted on 2012-03-24
2
Medium Priority
?
295 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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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

741 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