1

I have created an array from an HTML form containing the checkbox values.

I was wondering if it is possible to pass the selected checkbox values to jquery to use the Jquery code $('tr#myTableRow').remove(); for each array value that was posted by the form?

Any help is appreciated.

Code:

<form name="deletePost" id="deletePost" action="" method="post"> 
    <input class="checkBox" type="checkbox" id="idArray" name="idArray[]" value="1" />
    <input class="checkBox" type="checkbox" id="idArray" name="idArray[]" value="2" />
    <input class="formButtonDelete" type="submit" name="submit" value="Delete" />
</form>

$ids = $_POST['idArray'];
if(!empty($ids))
{
    foreach($ids as $id)
   {
      $sql = "DELETE FROM news WHERE id='$id'";
     mysql_query($sql);
   }
echo 'Posts Deleted - Please refesh page..';
}

I would like to use Jquery to remove the table rows that have the ids of the input values..

1
  • Can you please post your code? Commented Sep 15, 2012 at 2:35

1 Answer 1

1

Try this

$('input[name=submit]').click(function(){
    $('#deletePost input:checkbox').each(function(){
        if(this.checked){
            $(this).remove();
        }
    });
    return false;
});

I added return false; so you can see the input removed before submission, you may remove it to let the form submit

See this http://jsfiddle.net/F5Nth/

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

2 Comments

This just deletes the checkbox it self, I need it to delete the whole table row with the checkbox value id, lke so: <tr id="1"></tr> - $('#1').remove(); - like a for each loop in jquery to delete each row selected
I have modified this code and it works however I now have a new problem, check out stackoverflow.com/questions/12434861/…

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.