4

my script code and html is like this when i am trying to add new row it is automatically select property of last checkbox if chekbox is checked than in new row add checkbox with check want to remove checkbox checked in new row

script code

<script type="text/javascript">
  $("input.tr_clone_add").live('click', function() {
    var $tr    = $(this).closest('.tr_clone');
    var $clone = $tr.clone();
    $clone.find(':text').val('');
    $tr.after($clone);
});
</script>  

table look like this

   <table id="table-data" width="100%">
                  <tr class="tr_clone">
                    <td><input type="checkbox" autofocus name="status[]" value="Y"></td>
                    <td>
                      <select name="group_id[]">
                        <option>Select User</option>
                         <?php
                           $selectGroup = "SELECT  group_id,group_name
                                              FROM `group`";
                           $res = mysql_query($selectGroup);
                           while($row = mysql_fetch_array($res))
                           {
                             echo '<option value="'.$row['group_id'].'">'.$row['group_name'].'</option>';
                           }
                          ?>
                      </select>
                    </td>
                    <td><textarea name="address[]" rows="3" cols="35" placeholder="Enter Address"></textarea></td>
                    <td><input type="button" name="add" value="Add" class="tr_clone_add"></td>
                  </tr>
                </table>
1
  • Your explanation is incomprehensible. Also, please provide a small (trim everything which is not relevant to the question), simple example; ideally a complete HTML page one can test. Specifically, without PHP code in there. Commented May 21, 2015 at 10:34

3 Answers 3

2

check below code . you can find checkbox from cloned element using $clone.find('input[type=checkbox]') and set .attr('checked', false);

working DEMO

 $("input.tr_clone_add").live('click', function() {
  var $tr    = $(this).closest('.tr_clone');
  var $clone = $tr.clone();
  $clone.find(':text').val('');
  $clone.find(':checked').attr('checked', false);
   // or 
  // $clone.find('input[type=checkbox]').attr('checked', false);
  $tr.after($clone);
});
Sign up to request clarification or add additional context in comments.

1 Comment

happy to help you . pls accept answer if it will help you :)
1

Remove the checked property. Try with -

var $clone = $tr.clone().prop('checked', false);

OR

var $clone = $tr.clone().removeAttr('checked');

FIDDLE

Comments

0

Here is code...

 $("input.tr_clone_add").live('click', function() {

          var $tr    = $(this).closest('.tr_clone');
          var $clone = $tr.clone();
          var $clone = $tr.clone().prop('checked', false);
         //  or var $clone = $tr.clone().removeAttr('checked');

     });

This isn't new with jQuery 3: it was always the case that setting the checked property to false was better than removing the attribute. "In all other cases, .prop( "checked", false ) should be used instead." - I know you're quoting the jQuery people, but that's not correct either: you shouldn't say $(this).prop("checked", false) in cases when you can just say this.checked = false;

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.