views:

61

answers:

2

How do I get the values of a check box that is in a repeating region with its values dynamically generated from a recordset from the database.I want to retrieve the value when it is checked and after I click on a link.The problem is that it is retrieving only the first value of the recordset which is 1.This is the code:

jQuery:

$(document).ready(function() {
    $("#clickbtn").click(function() {
        $("input[type=checkbox][checked]").each(function() {
            var value=$("#checkid").attr('value');
            $("#textfield").attr('value',value);                     
        });
        return false;
    });
});

HTML:

<td width="22">
    <form id="form1" name="form1" method="post" action="">
        <input type="checkbox" name="checkid" id="checkid" value="<?php echo $row_people['NameID']; ?>" />
    </form>
</td>

I would appreciate the help

A: 

Try this:

$(document).ready(function() {
    $("#clickbtn").click(function() {
        $("input[type=checkbox]").each(function() {

            if ($(this)).is(':checked'))
            {
              var value=$("#checkid").attr('value');
              $("#textfield").attr('value',value);
            }

        });
        return false;
    });
});
Sarfraz
+1  A: 

As Nick Craver, said, your ID should definitely be unique. The problem, however, is with your javascript:

$("input[type=checkbox][checked]").each(function() {
    var value=$("#checkid").attr('value');
    $("#textfield").attr('value',value);                     
});

What you're doing here is selecting all checked checkboxes, but only grabbing the value for the input with id=checkid. You need to actually iterate over the checkboxes that are passed into the iterator, which can be done by replacing #checkid with this:

$("input[type=checkbox][checked]").each(function() {
    var value=$(this).attr('value');
    $("#textfield").attr('value',value);                     
});
andymism
Thanx bro, it worked.
John