Page 1 of 1

jQuery checkbox

Posted: Thu Jun 24, 2010 12:28 am
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?

Re: jQuery checkbox

Posted: Thu Jun 24, 2010 5:56 am
by Weirdan
There's couple of issues with your code, it's probably easier to just show the solution: http://jsfiddle.net/JCsRX/

Re: jQuery checkbox

Posted: Thu Jun 24, 2010 6:14 am
by Nikas
Can you check out this?

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

I am still unable to get it running correctly.

Re: jQuery checkbox

Posted: Thu Jun 24, 2010 7:30 am
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.

Re: jQuery checkbox

Posted: Thu Jun 24, 2010 1:52 pm
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