Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2009, 09:16 PM   PM User | #1
sdsdsd
New Coder

 
Join Date: Feb 2009
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
sdsdsd is an unknown quantity at this point
Question How to detect a check box value in a row?

I have a table with variable number of rows. Each row has two columns. The first column has check boxes which user can select or deselect. The second column has some text. When user clicks on a button on the page, for each row, I need to see if the check box is checked and if so, I need to get the text in the second column for the corresponding row. How can I do this using jQuery? Thanks.
sdsdsd is offline   Reply With Quote
Old 10-06-2009, 04:18 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
The easy way is to relate the checkbox with the text's container using the ID, class, or some other attribute. Actually I'd use class, so you can assign the same name to each (IDs should be unique).

PHP Code:
<input type="checkbox" class="chk100"><span class="chk100">Text1</span><br />
<
input type="checkbox" class="chk200"><span class="chk200">Text2</span><br />
<
input type="checkbox" class="chk300"><span class="chk300">Text3</span><br />
<
input type="button" id="btn"
Then find all checked checkboxes and get the text for each:

PHP Code:
$(function() {
    $(
"#btn").click(function() {
        var 
textArray = [];
        $(
"input:checked").each(function() {
            
textArray.push($("span." + $(this).attr("class")).text());
        });
        
//just to demonstrate that values are now in the array
        
for (var i in textArray) {
            
alert(textArray[i]);
        }
    });
}); 
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:10 PM.


Advertisement
Log in to turn off these ads.