Need help with a form check function.
Posted: Mon Feb 11, 2008 4:30 pm
Can anyone tell me why the checkform() function isn't working
Since I'm not even geting the "Testing" alert box it means the function isn't even being called, no idea why though.
I'm sorry if I'm doing something really stupid, it's been a while since I last did anything in PHP.
*edit* This probably should have been in the "Miscellaneous" since it might be more Javascript related then PHP. Sorry about that.
Code: Select all
<!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=iso-8859-1" />
<script>
function checkform() {
if(document.testinho.qtd[<?=$reg_lista['ID_produto']?>].value<"0") {
alert("Valor inválido.")
return false;
}
alert("Testing.");
return true;
}
</script>
<title>Amazonia</title>
<link type="text/css" rel="stylesheet" href="estilos.css"/>
<style type="text/css">
<!--
.style1 { font-size: 12px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div class="wrapper">
<div class="banner"><a href="#"><img src="images/logo_10.jpg" alt="AMAZONIA" width="351" height="108" border="0" /></a></div>
<div class="content">
<div class="leftcolumn">
<ul>
<?php
if (!(isset($_SESSION['MM_Username']))) {
?>
<li><a href="login.php">Login</a></li>
<li><a href="registo.php">Registo</a></li>
<li><a href="esqueci.php">Esqueci-me</a></li>
<?php } else { ?>
<li><a href="<?php echo $logoutAction ?>">Logout</a></li>
<li><a href="alterar.php">Alterar Dados</a></li>
<li><a href="historico.php">Histórico</a></li>
<?php
}
?>
</ul>
<div id="navvy">
<ul id="navvylist">
<li><a href="index.php">Novidades</a></li>
<li><a href="livros.php">Livros</a></li>
<li><a href="filmes.php">Filmes</a></li>
<li><a href="musica.php">Música</a></li>
<li><a href="pesquisa.php">Pesquisar</a></li>
</ul>
</div>
</div>
<div class="rightcolumn">
<h2>Carrinho de compras</h2>
<div class="article">
<form name="testinho" action="cart.php?action=altera_qtd" method="post" onsubmit='[b]return checkform()[/b]'>
<p> </p>
<table border="1" width"100%">
<tr>
<td width="120"><div align="center"><strong>PRODUTO</strong></div></td>
<td width="100"><div align="center"><strong>REMOVER</strong></div></td>
<td width="80"><div align="center"><strong>PREÇO</strong></div></td>
<td width="80"><div align="center"><strong>QTD6</strong></div></td>
<td width="100"><div align="center"><strong>SUBTOTAL</strong></div></td>
</tr>
<?
$sql_lista = "SELECT * FROM Carrinho WHERE sessao ='".session_id()."' ORDER BY titulo ASC";
$exe_lista = mysql_query($sql_lista) or die(mysql_error());
$num_lista = mysql_num_rows($exe_lista);
if ($num_lista > 0) {
$total_carrinho = 0;
while ($reg_lista = mysql_fetch_array($exe_lista, MYSQL_ASSOC)){
$total_carrinho += ($reg_lista['preco']*$reg_lista['qtd']);
?>
<tr>
<td><?=$reg_lista['titulo']?>
<div align="center"></div></td>
<td><div align="center"><a href="cart.php?action=del&ID_produto=<?=$reg_lista['ID_produto']?>">X</a></div></td>
<td><?=$reg_lista['preco']?>
<div align="center"></div></td>
<td><div align="center">
<input type="text" size="3" name="qtd[<?=$reg_lista['ID_produto']?>]" value="<?=$reg_lista['qtd']?>"/>
</div></td>
<td><?=number_format(($reg_lista['preco']*$reg_lista['qtd']),2, ",",".")?>
<div align="center"></div></td>
</tr>
<?
}
}
?>
<tr>
<td colspan="4"><div align="right">Total</div></td>
<td><?=number_format($total_carrinho,2, ",",".")?>
<div align="center"></div></td>
</tr>
</table>
<p align="right"> </p>
<p align="right"><a href="index.php">Adicionar mais compras ao carrinho</a></p>
<p align="right">
<input type="submit" class="button" value="Alterar quantidade"/>
</p>
</form>
<form action="compra.php" method="post">
<label>
<div align="right">
<input name="confirmar" type="submit" class="button" id="confirmar" value="Comprar" />
</div>
</label></form>
</div>
</div>
<div class="clear"></div>
</div>
<div class="footer">Amazónia SI</div>
</div>
</body>
</html>I'm sorry if I'm doing something really stupid, it's been a while since I last did anything in PHP.
*edit* This probably should have been in the "Miscellaneous" since it might be more Javascript related then PHP. Sorry about that.