Page 1 of 1

Javascript/PHP probelm

Posted: Wed Mar 02, 2005 5:29 pm
by mmc01ms
I've created a script which displays a list of orders. If a customer wishes to cancel an order some javascript asks if they are sure selecting yes will execute to the cancelorder script. The problem is once yes is selected nothing happens and an error box appears in the bottom of the browser saying:

object doesn't support this method?

Code: Select all

<?php
	
	
	//myaccount_functions.php written by Manpreet Sandhu 13/02/2005
	
	require_once('shopping_basket_fns.php');
	
?>


<script> 
	function checkIt()&#123; 
		if(confirm("Cancel Order?"))&#123; 
			document.MyForm.submit();
			//return true; 
		&#125; 
	&#125; 
</script> 





<?php
	
	
	function get_outstanding_order_details($customer_id)&#123;
		//connects to the database and creates an array with the outstanding orders
		$link_id = db_connect();
		$query = "select orders.delivery_charge, orders.order_id, orders.customer_id, orders.total, ordered_items.cat_no, vinyls.title, vinyls.price, ordered_items.order_item_status, orders.date_order_placed 
				from orders , ordered_items , vinyls
				where orders.order_id = ordered_items.order_id
				and ordered_items.cat_no = vinyls.cat_no
				and ordered_items.order_item_status = 'On Order'
				or ordered_items.order_item_status = 'Awaiting Stock'
				order by date_order_placed desc";
			$result = @mysql_query($query, $link_id) or die ("There was a problem with this query.");
		
		if (!$result)
			return false;
		$num_orders = @mysql_num_rows($result);
		if($num_orders == 0)
			return false;
		
		$result = db_result_to_array($result);
		return $result;
	&#125;
	
	function display_outstanding_orders($order_array)
	&#123;// used to display the outstanding orders
		if(!is_array($order_array))
		&#123;
			echo 'No outstanding orders<br />';
			return;
		&#125;
		
		&#123;
?>
<table bgcolor="#7b9815" border="0" bordercolor="FFFFFF" cellpadding="0" cellspacing="0">
	<th width="425">Outstanding Orders</th>
</table>
<br>
<table bgcolor="#7b9815" border="1" bordercolor="FFFFFF" cellpadding="0" cellspacing="0">
	<font color="#000000" size="1" face="Arial, Helvetica, sans-serif"><th>Order Date</th><th>Item</th><th>Price</th><th>Status</th></font>
	<?
		&#125;
		foreach ($order_array as $row)
		&#123;//while an order still exists in the array loop round and display again.
			
			$url = 'show_vinyls.php?cat_no='.($row&#1111;'cat_no']);
			$title = $row&#1111;'title'];
			$price = $row&#1111;'price'];
			$order_date = $row&#1111;'date_order_placed'];
			$status = $row&#1111;'order_item_status'];
			$cat_no = $row&#1111;'cat_no'];
			$order_id = $row&#1111;'order_id'];
			
			
			&#123;
	?> <tr>
		
		<?
			&#125;
			
			
			print '<tr>';
			print '<td>';
			echo $row&#1111;'date_order_placed'];
			echo '</td>';
			//echo '<td>';
			print do_html_url($url,$title);
			echo '</td>';
			echo '<td>';
			echo $row&#1111;'price'];
			echo '</td>';
			echo '<td>';
			echo $row&#1111;'order_item_status'];
			echo '</td>';
			
			echo '<td>';
			echo '<form name="MyForm" action="cancelorder.php"> ';
			echo '<input type="button" value="Cancel Order" onClick="checkIt();"> ';
			echo '<input type="hidden" name="cat_no" value="'.$row&#1111;'cat_no'].'">';
			echo '</form>';
			echo '</td>';
			
			echo '</tr>';
			
		&#125;
			echo '</table>';
		&#125;

Posted: Wed Mar 02, 2005 5:42 pm
by feyd
Moved to Client-side.

Posted: Thu Mar 03, 2005 3:14 am
by CoderGoblin
Three possible solutions as far as I can see...

1)

Code: Select all

function checkIt()
  &#123;
      if(confirm("Cancel Order?"))&#123;
         return true;
      &#125; else &#123;
         return false;
   &#125;
2) change the

Code: Select all

echo '<input type="button" value="Cancel Order" onClick="checkIt();"> ';
to

Code: Select all

echo '<input type="submit" name="doit" value="Cancel Order" onClick="checkIt();"> ';
3) Try inserting a hidden submit button.

Code: Select all

echo '<form name="MyForm" action="cancelorder.php"> ';
         echo '<input type="button" value="Cancel Order" onClick="checkIt();"> ';
         echo '<input type="hidden" name="cat_no" value="'.$row&#1111;'cat_no'].'">';
         echo '<input type="submit" name="hidden_submit" value="doit" style="display:none;">';

I have run into this problem before, only to find it was because I named the submit button "submit" which was causing some confusion. This is not the case here but thought I would mention it for others.