Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Jquery/JS Help with Checkboxes as Triggers
Old 12-27-2010, 11:16 PM Jquery/JS Help with Checkboxes as Triggers
Junior Talker

Posts: 2
Name: Neal
Location: Iowa/SoCal
Trades: 0
I am trying to make a JS script (utilizing Jquery) to make certain tablerows appear or disappear based upon whether a checkbox is checked or unchecked. I was experimenting with buttons to make these tablerows appear/disappear and was successful, but now I want to make it work for checkboxes. This is my first JS code I've tried to write, so please excuse the noob in me.

I did some checking, and apparently the cat function is not even called... hmm


Code:
$(document).ready(function(){
    
function cat(cat) {
        if (getElementById("#" + cat + "\"").checked) {
            $("[cat='" + cat + "']").addClass("show");
            $("[cat='" + cat + "']").removeClass("hide");
    } else {
            $("[cat='" + cat + "']").addClass("hide");
            $("[cat='" + cat + "']").removeClass("show");
            }
}


$("#Art").click(cat("Art"); alert("sometext"););


});
Code:
<form>
Categories:<br />
<input type="checkbox" id="Art" /> Art<br />
<input type="checkbox" id="Academic" /> Academic<br />
<input type="checkbox" id="Environment" /> Environment<br />
<input type="checkbox" id="Sports" /> Sports<br />
<br />
Schools:<br />
<input type="checkbox" id="5C" /> Five-College<br />
<input type="checkbox" id="CM" /> Claremont McKenna<br />
<input type="checkbox" id="CM" /> Harvey Mudd<br />
<input type="checkbox" id="PZ" /> Pitzer<br />
<input type="checkbox" id="PO" /> Pomona<br />
<input type="checkbox" id="SC" /> Scripps<br /><br />
</form>
Any help would be greatly appreciated! I have done a lot of Googleing to no avail.
NealJ2K is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-28-2010, 12:56 AM Re: Jquery/JS Help with Checkboxes as Triggers
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Not sure if this is what you mean:

HTML Code:
<script type="text/javascript">
<!--

$(document).ready(function() {

    $('.hideThis').hide();
    $('.checkBox').click(function() {
        $('.hideThis').toggle();
    });

});


//-->
</script>

<form action="" method="post">
    <label>Show me the hidden animals:</label> <input type="checkbox" name="something" class="checkBox" />
</form>

<table border="1" width="100%">
    <tr class="hideThis">
        <td>Dog</td>
        <td>Cat</td>
    </tr>
    <tr>
        <td>Birds</td>
        <td>Fish</td>
    </tr>
</table>
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 12-28-2010, 01:21 AM Re: Jquery/JS Help with Checkboxes as Triggers
Junior Talker

Posts: 2
Name: Neal
Location: Iowa/SoCal
Trades: 0
Exactly what I meant! Thank you so much! I played around with it for another 2 hours after that post with no luck. Thank you!
NealJ2K is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Jquery/JS Help with Checkboxes as Triggers
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12924 seconds with 12 queries