简体   繁体   中英

How can I show selected checkboxes in alert window before form submit?

I have a form for editing and deleteing phone directory entries for our office. Each line shows the persons' name and phone number etc, and has a checkbox.

The form basically has two buttons, edit and delete. You go through and select all the rows that you either want edit or delete, and then the form is submitted.

What I want to do, is have an alert when the delete button is pressed, that asks for confirmation before deleting. What I would like to do, is to list out all the rows that were marked for deletion in this alert window.

I'm not sure if this is possible, as the POST data isnt available until the form is submitted, which in turn would be prevented by the alert window.

Would this be possible using PHP and javascript? I have included some code examples below:

<form name="manage" method="post" action="edit.php">
    <input type="submit" name="add" value="Add">
    <input type="submit" name="edit" value="Edit">
    <input type="submit" name="delete" value="Delete">

//For each row found
while($row = mysql_fetch_assoc($result)) {
    //Echo out a row with details
    echo "<tr>
        <td><input type='checkbox' name='dirid[]' value='".$row['Dir ID']."' /></td>
        <td>".$row['Floor']."</td>
        <td>".$row['First Name']."</td>
        <td>".$row['Last Name']."</td>
        <td>".$row['Extension']."</td>
        <td>".$row['Department']."</td>
        </tr>";
}
</form>

At the moment, all that is posted, is the dirid, which is just a unique ID for each row in the table. The delete script then queries the database, and removes each row for each of those ID's

I suppose that if it is not possible in an alert window, I could also send the ID's to the delete script, show them on the page with a confirm button, and then put and alert on top of that as well, but seems a bit long winded.

Any suggestion greatly appreciated.

Eds

也许可以在这里使用jquery来实现,例如http://jsfiddle.net/damian_silvera/Cxqp5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM