0

I am working on a html page. The page has a table with 3 columns and a button. One of the columns of the table is a check box (The number of rows are changed dynamically):

<table cellpadding="0" cellspacing="0" border="1" class="display" id="tag" width="100%">
    <tbody>
        <tr>
            <td align="center">
                <input type="checkbox" class="case" name="case" value="0"/>
            <td>fruit</td>
            <td>apple</td>
        </tr>
        <tr>
            <td align="center">
                <input type="checkbox" class="case" name="case" value="1"/>
            <td>fruit</td>
            <td>pear</td>
        </tr>
    </tbody>
</table>
<p><input type="button" value="Generate" onclick="generate()"></p>

When user click the "Generate" button, the generate() function will generate a special string base on the column of each row.

My question is that how can I check if the "checkbox" row is checked or not? I would like to filter those non-checked rows when I generate the string.

Thanks.

2
  • 1
    No idea whatsoever what you are asking. Please try again... Commented Dec 12, 2012 at 0:45
  • Sorry. I have rewritten my question. Commented Dec 12, 2012 at 1:05

2 Answers 2

3

Filter the rows based upon which have a checked checkbox:

var rows = $(".case:checked").closest("tr");

This returns a jQuery object that contains all of your table rows housing checked checkboxes.

Sign up to request clarification or add additional context in comments.

Comments

0

Call getElementsByName will give you an array of references of your checkboxes. Loop the array in order to get the values.

var arr = document.getElementsByName("case");
for(i = 0; i < arr.length; i++){
   if(arr[i].checked){
      doSomething;
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.