hi, in my shopping cart we have a phone orders and when user tells products we will click on that product and calculate the total and insert in to database
my code is like

<table width="100%" border="0" align="left" cellpadding="3" cellspacing="1" class="borent">
                          <? 	$s=-1;
						while ($prow = mysql_fetch_assoc($pres)) {
						$s++;
						$item[$s]=$prow['p_id'];
						$p123[$s]=$prow['p_price'];
					// discount calculation
					//
					?>
		
					
                          <tr>
                            <td width="38%" align="left" valign="top"><span class="bulkname">&nbsp;<?php echo $prow['p_name'];?></span></td>
                            <td width="18%" align="center" valign="top">Rs.<span class="red"><?php echo number_format($prow['p_price'],2);?> </span>Per <? echo getdata("tbl_measurement","name","id='".$prow['p_measurement']."'");?></td>
                            <td width="15%" align="center" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;
                                <input name="PROD_<? echo $s;?>" type="text" class="box"   id="PROD_<? echo $s;?>" onKeyUp="calculatetotal()"  value="1"  size="1"/>
                                <input name="price<? echo $s;?>"  id="price<? echo $s;?>" type="hidden"  size="1"  value="<?php echo $prow['p_price'];?>">
                                <input name="ids[]"  id="ids[]" type="hidden"  size="1"  value="<?php echo $prow['p_id'];?>">
								
                              &nbsp;<? echo getdata("tbl_measurement","name","id='".$prow['p_measurement']."'");?></td>
                            <td width="9%" align="center" valign="top"><label>
                              <input type="checkbox" name="chek<? echo $s;?>" id="chek<? echo $s;?>" value="1" onClick="calculatetotal()" /></label>
							  <input name="order<?=$s;?>" type="hidden" value="" size="2"></td>
                            <td width="20%" align="center" valign="top"><div id="subprice<? echo $s;?>" class="text5"></div></td>
                            <? }?>
                          </tr>
                        </table>

the javascript function is

function calculatetotal(){


var tot=0;

for (var i=0; i <=<?=$s;?>;i++) {

if (OnlyNumbers(document.getElementById("PROD_"+i))==0){return false;}

 if(document.getElementById("chek"+i).checked==true){
 
 if(document.getElementById("PROD_"+i).value<=0){
 alert("Minimum Quantity To Be Entered is 1");
  document.getElementById("PROD_"+i).value=1
  
   document.getElementById("PROD_"+i).focus();
   document.getElementById("PROD_"+i).select();
  document.getElementById("chek"+i).checked==false
  return false;
   
 }
subtot=document.getElementById("price"+i).value*document.getElementById("PROD_"+i).value
document.getElementById("subprice"+i).innerHTML=subtot
tot=tot+subtot;

}else{
document.getElementById("subprice"+i).innerHTML="";
}
   } 
 document.getElementById("TOTAL").innerHTML=tot
}

now i want is when onclick event takes place in order hidden variable the should be increment by 1

help me
thanks in advance

ok here is a work around as I think that I have the idea of what you are trying to achieve though I cannot be sure.

1st off it seems that you need to know the total number of products that you have on the screen as then in the Javascript you go through all of them to see if they are set.

If this thinking is right then the easy way to sort out your problem is to do

In your PHP function do this.

$totalproducts = mysql_num_rows($prow);

This gives you the total number of rows returned from the database by your query.

Then when you have the onclick event do this

onClick="calculatetotal(<?php $totalproducts ?>);"

Then in your Javascript do this.

function calculatetotal(totalproducts){


var tot=0;

for (var i=0; i <=totalproducts;i++)
{
..........
}

This article has been dead for over six months. Start a new discussion instead.