javascript - Where should I place return false;? -
i have shopping cart script works fine except after item add together cart jumps top of page. everywhere place return false:
it stops info beingness added shoppingcart.php page.
php this:
<?php include("includes/db.php"); include("includes/functions.php"); if ( isset($_request['command']) && $_request['command'] == 'add' && $_request['productid']>0 ) { $pid=$_request['productid']; addtocart($pid,1); } ?>
javascript this:
<script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit() ; confirm('you have added item cart ') ; }
this functions page.
<?php function get_product_name($pid){ $result=mysql_query("select name employees id=$pid"); $row=mysql_fetch_array($result)or die(mysql_error()); homecoming $row['xname']; } function get_price($pid){ $result=mysql_query("select cost xxxxxx id=$pid"); $row=mysql_fetch_array($result); homecoming $row['price']; } function remove_product($pid){ $pid=intval($pid); $max=count($_session['cart']); for($i=0;$i<$max;$i++){ if($pid==$_session['cart'][$i]['productid']){ unset($_session['cart'][$i]); break; } } $_session['cart']=array_values($_session['cart']); } function get_order_total(){ $max=count($_session['cart']); $sum=0; for($i=0;$i<$max;$i++){ $pid=$_session['cart'][$i]['productid']; $q=$_session['cart'][$i]['qty']; $price=get_price($pid); $sum+=$price*$q; } homecoming $sum; } function addtocart($pid,$q){ if($pid<1 or $q<1) return; if(is_array($_session['cart'])){ if(product_exists($pid)) return; $max=count($_session['cart']); $_session['cart'][$max]['productid']=$pid; $_session['cart'][$max]['qty']=$q; } else{ $_session['cart']=array(); $_session['cart'][0]['productid']=$pid; $_session['cart'][0]['qty']=$q; } } function product_exists($pid){ $pid=intval($pid); $max=count($_session['cart']); $flag=0; for($i=0;$i<$max;$i++){ if($pid==$_session['cart'][$i]['productid']){ $flag=1; break; } } homecoming $flag; } ?>
or should using different request?
javascript php
No comments:
Post a Comment