Solved

Jquery radiobutton show hide div question

Posted on 2009-07-13
2
2,771 Views
Last Modified: 2012-05-07
Hi there, i have two radio buttons that should show/hide two divs, I am using jquery here is my code, as far as i can tell both divs are hidden on load but the checkbox does not show them. using the latest jquery.
<script type="text/javascript">
    $(document).ready(function(){
	$("#hourlydiv, #fixedfee").hide();
    
	if($("input[name='type']:checked").val() =="hourly") {
            $("#hourlydiv").show("fast");
            $("#fixedfeediv").hide("fast");
	} else if ($("input[name='type']:checked").val() =="fixed") {
            $("#hourlydiv").hide("fast");
            $("#fixedfeediv").Show("fast");
	}
});
 
     </script>

Open in new window

0
Comment
Question by:cookiejest
2 Comments
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 200 total points
ID: 24842150
you need to create an onclick function that will show/hide the div's, the ready function will only be called when the page is done loading.
0
 
LVL 4

Accepted Solution

by:
SadafRasheed earned 300 total points
ID: 24842842
try this
<script type="text/javascript">
    $(document).ready(function(){
        $("#hourlydiv, #fixedfee").hide();
    
		$("input[name='type']").click(function (){
		
			if($("input[name='type']:checked").val() == "hourly" ) {
				$("#hourlydiv").show("fast");
				$("#fixedfeediv").hide("fast");
			} else if ($("input[name='type']:checked").val() =="fixed") {
				$("#hourlydiv").hide("fast");
				$("#fixedfeediv").Show("fast");
			}
		});
		
        
});
 
</script>

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
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…

679 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