Jump to content


Text Link As Submit Button

  • Please log in to reply
3 replies to this topic

#1 Eiolon

  • Members
  • PipPipPip
  • Advanced Member
  • 357 posts

Posted 28 December 2012 - 07:58 PM

I am going to guess this is a problem with javascript, because I can use a typical submit button and have it work.

I am trying to make it so a text link acts as the submit button and have it delete records that are selected via checkbox.

When I click the delete items button it just refreshes the page and removes the check from the box. The record is still there. If I use a submit button it works.

I have for the link:

<a href="#" onclick="document.forms['delete_items'].submit();" title="Delete Items">Delete Items</a>

I have for my form:

<form id="delete_items" name="delete_items" method="POST" action="">

	<table class="data">
	 <tr style="background:#F1F1F1;">
	 <td style="width:20px"></td>
	 <td style="width:80px">Received</td>
	 <td style="width:80px">Returned</td>
	 <td style="width:80px">Method</td>
	 <?php while ($row_returns = $sth_returns->fetch(PDO::FETCH_ASSOC)) { ?>
	 <tr onmouseover="this.bgColor='#EBFAFF';" onmouseout="this.bgColor='#FFFFFF';">
	 <td><input type="checkbox" name="<?php echo $row_returns['id'] ?>" value="<?php echo $row_returns['id'] ?>" style="border:none;" /></td>
	 <td><?php echo htmlspecialchars($row_returns['item'], ENT_QUOTES, 'UTF-8'); ?></td>
	 <td><?php echo htmlspecialchars($row_returns['owner'], ENT_QUOTES, 'UTF-8'); ?></td>
	 <td><?php echo htmlspecialchars($row_returns['date_received'], ENT_QUOTES, 'UTF-8'); ?></td>
	 <td><?php echo htmlspecialchars($row_returns['date_returned'], ENT_QUOTES, 'UTF-8'); ?></td>
	 <td><?php echo htmlspecialchars($row_returns['method'], ENT_QUOTES, 'UTF-8'); ?></td>
	 <?php } ?>



I have for my PHP script:

if ($_POST['id'] ) {
foreach($_POST as $id) {
$sth_delete_item = $dbh_mysql->prepare('
FROM returns
WHERE id = :id
$sth_delete_item->bindParam(':id', $id);
header("Location: index.php");


Edited by Eiolon, 28 December 2012 - 07:59 PM.

#2 nogray

  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 28 December 2012 - 08:51 PM

From what I can see, you are trying to delete $_POST[id] but none of your checkboxes is named "id". If you view the source code (in your browser), you'll probably see the name as a number. Also, some servers don't pass arrays from your HTML form and you'll only get a string value "Array", you might want to check that as well.


#3 Eiolon

  • Members
  • PipPipPip
  • Advanced Member
  • 357 posts

Posted 28 December 2012 - 09:15 PM

Thanks, problem solved!

#4 Adam

  • Moderators
  • Advanced Member
  • 5,730 posts
  • LocationSheffield / UK

Posted 30 December 2012 - 12:00 AM

Have you considered styling a submit button as a link by the way, to avoid the JS dependency?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users