Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Wagner Martins - SC

Excluir Itens

Recommended Posts

Olá,

 

Não estou conseguindo excluir os itens de uma lista gerada pelo usuario do site.

 

Meu código é esse:

 

function del(pid){
	if(confirm('Do you really mean to delete this item')){
		document.form1.pid.value=pid;
		document.form1.command.value='delete';
		document.form1.submit();
	}

<a href="javascript:del(<?=$pid?>)">Remove</a>

 

O valor do $pid esta sendo passado corretamente, eu consigo imprimir na tela o valor de $pid

Compartilhar este post


Link para o post
Compartilhar em outros sites

O prompt de confirmaçao aparce sim, o nome do form eh form1 tbm. No firefox aparece esse erro Hora:

 

02/08/12 10:21:23
Erro: TypeError: document.form1 is undefined
Arquivo-fonte: http://www.ibrap.ind.br/shoppingcart.php
Linha: 16

 

 

<?
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
	remove_product($_REQUEST['pid']);
}
else if($_REQUEST['command']=='clear'){
	unset($_SESSION['cart']);
}
else if($_REQUEST['command']=='update'){
	$max=count($_SESSION['cart']);
	for($i=0;$i<$max;$i++){
		$pid=$_SESSION['cart'][$i]['productid'];
		$q=intval($_REQUEST['product'.$pid]);
		if($q>0 && $q<=999){
			$_SESSION['cart'][$i]['qty']=$q;
		}
		else{
			$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<script language="javascript">
function del(pid){
	if(confirm('Do you really mean to delete this item')){
		document.form1.productid.value=pid;
		document.form1.command.value='delete';
		document.form1.submit();
	}
}
function clear_cart(){
	if(confirm('This will empty your shopping cart, continue?')){
		document.form1.command.value='clear';
		document.form1.submit();
	}
}
function update_cart(){
	document.form1.command.value='update';
	document.form1.submit();
}


</script>
</head>

<body>
<form nome="form1" method="post">
<input type="hidden" nome="pid" />
<input type="hidden" nome="command" />
<div style="margin:0px auto; width:600px;" >
   <div style="padding-bottom:10px">
   	<h1 align="center">Your Shopping Cart</h1>
   <input type="button" value="Continue Shopping" onclick="window.location='products.php'" />
   </div>
   	<div style="color:#F00"><?=$msg?></div>
   	<table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
   	<?
		if(is_array($_SESSION['cart'])){
           	echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>nome</td</tr>';
			$max=count($_SESSION['cart']);
			for($i=0;$i<$max;$i++){
				$pid=$_SESSION['cart'][$i]['productid'];
				$q=$_SESSION['cart'][$i]['qty'];
				$pnome=get_product_nome($pid);
				if($q==0) continue;
		?>
           		<tr bgcolor="#FFFFFF"><td><?=$i+1?></td><td><?=$pid?> - <?=$pnome?></td>
                   <td><a href="javascript:del(<?=$pid?>)">Remove</a></td></tr>
           <?					
			}
			echo " Pid: $pid";

		?>
			<tr><td><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"> <input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr>
		<?
           }
		else{
			echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
		}
	?>
       </table>
   </div>
</form>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Blza Lucas Lima,

 

Agora funcionou o botão para limpar a lista, mais o botat de excluir um item ainda não esta funcionando, acho q não ta passando o valor de pid :ermm:

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.