jQuery checkbox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Nikas
Forum Newbie
Posts: 12
Joined: Thu Jun 24, 2010 12:05 am

jQuery checkbox

Post by Nikas »

I have 5 checkbox, namely: A, B, C, D, E

When the user click on checkbox C, it will activate the jQuery and display the hidden div.

And this is my HTML:

Code: Select all

<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Contract">Contract</option><br />
<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Temporary">Temporary</option><br />
<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Part-Time">Part-Time</option><br />    
<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Permanent">Permanent</option><br />
<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Home-based">Home-based</option><br />
<input type="checkbox" id="typeJobs" name="typeJobs[]" value="Internship">Internship</option>  
My DIV:
[text]<div class="hide" id="Part-Time"><?php echo displayFields('Part-Time'); ?></div>[/text]

jQuery:

Code: Select all

$(document).ready(function(){  
    $("#typeJobs").click(function(){  
        if ($("#typeJobs:checked").val() == "Part-Time" ) {  
            $("#Part-Time").slideDown("fast"); //Slide Down Effect  
        } else {  
            $("#Part-Time").slideUp("fast");    //Slide Up Effect  
        }  
      
    });  
});
However, it doesn't work. Anyone?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: jQuery checkbox

Post by Weirdan »

There's couple of issues with your code, it's probably easier to just show the solution: http://jsfiddle.net/JCsRX/
Nikas
Forum Newbie
Posts: 12
Joined: Thu Jun 24, 2010 12:05 am

Re: jQuery checkbox

Post by Nikas »

Can you check out this?

http://jsfiddle.net/JCsRX/1/

I am still unable to get it running correctly.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: jQuery checkbox

Post by Weirdan »

Nikas wrote:Can you check out this?

http://jsfiddle.net/JCsRX/1/

I am still unable to get it running correctly.
There's a tiny typo:
$(document).read(... should be $(document).ready(...

Also you have unmatched closing </option> tags there - it doesn't seem to harm, but makes your html invalid.
Nikas
Forum Newbie
Posts: 12
Joined: Thu Jun 24, 2010 12:05 am

Re: jQuery checkbox

Post by Nikas »

Oops.. Thanks for pointing out.

And the </option> isn't suppose to be there. Made the changes on my side.

Thanks for the help. :D
Post Reply