How to replace checkbox that passes an array

Discussion in 'JavaScript' started by patter, Jul 1, 2013.

  1. #1
    I have a php file with the following javascript that uses a checkbox to delete an item. I want to replace that with just text. I've tried the change below but there are two problems: First, I don't want the id to be displayed on the page. It should be the word Delete. And second, the form submits an array and that is not being passed correctly for some reason.

    function checkDeleteBox(checkboxid) {
      document.myform.submit();
    }
     
    <form name="myform" action="test.php?process=handle_delete" method="post">
    <input type="text" name="all_ids[]" value="1" size="4">
    <input type="text" name="delete1[]" value="7", onclick="javascript:checkDeleteBox('7');" id="7">
    <input type="checkbox" name="delete2[]" value="7", onclick="javascript:checkDeleteBox('7');" id="7">
     
    <input type="submit" name="do_delete" value="Delete">
    Code (markup):
    If I click on the checkbox, this is the output
    If I click on the text link, this is the output
    The all_ids is used to compare against for the delete and is used elsewhere in the code. So the php code checks if the id in the delete array is in the all_ids array. But the second method just duplicates it so all compares work and everything is deleted.

    I thought about using a hidden field for the array and then a submit link and that did work for the deletion. But the deletion was done with every click and that shouldn't happen in all cases.

    There may be an easier way to do this with jquery but the code in the project isn't setup for it and the above code is used in a number of places so I would prefer to stick with a javascript solution to avoid having to make too many changes.

    Can someone please point out the correct way to do this?
     
    patter, Jul 1, 2013 IP