sarithak 0 Junior Poster

Hi...
here i am doing a project like shopping cart....
when we submit Quantity& Cost...it requires mutiplication...when we enterd these two values,it display total amount in that same page itself...


So,here it requires onfocus event...plz tell me how we can use here...and also check this below form ....provide hidden fields plz.....

<?php 
			session_start();
			$sname=$_GET['sname'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>:: Vet ::</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="description" content="Small Corporation" />
	<meta name="keywords" content="small, corporation" />
	<link rel="stylesheet" href="../style.css" type="text/css" />
    <script type="text/javascript" src="../easyscroll/easyscroll.js"></script>
 <script language="javascript">
	 function switchProduct()
	 {
	 if(window.document.form.icode.options.selectedIndex!=0)
	 
	 window.location=window.document.form.icode.options[window.document.form.icode.options.selectedIndex].value
	 }
	  
	 
	  </script>

    <style type="text/css">
<!--
.style1 {
	color: #9966FF;
	font-weight: bold;
}
.style2 {color: #808080}
-->
    </style>
</head>
<body>

	<div id="content">
	  <ul id="menu" >
		<li></li>
		<li><a href="home.php?sname=<?php echo $sname;?>">Stock Records</a> |</li>
			<li><a href="sale.php?sname=<?php echo $sname;?>">Sale</a>|<a href="changepassword.php">Changepassword</a></li>
	  </ul>
		
		<div class="style1" id="main">
		  <div align="center">
		    <table width="67%" height="90" border="0">
            <tr>
              <td width="30%"><div align="center">Item Code</div></td>
              <td width="29%"><div align="center">Item Name</div></td>
              <td width="27%"><div align="center">Quantity</div></td>
              <td width="14%"><div align="center">cost</div></td>
            </tr> 
            
             <?php
		
	
		include("configitems.php");
		if($iname==""){
        
        $ress = mysql_query("SELECT icode FROM $sname")or die(mysql_error());
		?>
            
           <form id="form" method="post" name="form" action="sale.php?qty=<?php echo $_GET['qty'] ; ?>&cost=<?php echo $_GET['cost']; ?>">
            <tr>
              <td><select name="icode"  onchange="switchProduct()">
                <option selected="selected"></option>
                <?php 
				while ($row = mysql_fetch_array($ress))
	  			{ 
				$icode=  $row['icode'];?>
                <option   value="sale.php?sname=<?php echo $sname ; ?>&icode=<?php echo $icode ; ?>">
                <?php  
	   echo $icode; 
	 echo "<br>";
	
?>
                </option>
                <?php }  }  ?>
              </select></td>
              <?php
              $icode1=$_GET['icode'];
			 
                $ress1 = mysql_query("SELECT * FROM $sname where icode='$icode1'")or die(mysql_error());
			  
				$row = mysql_fetch_array($ress1);
	  			
				 $iname=  $row['iname'];
				$cost=  $row['cost'];
			  ?>
              <td><input type="text" name="iname" id="textfield2"  value="<?php echo $iname ; ?>"/></td>
              <td><input type="text" name="qty" id="textfield3" /></td>
              <td><input type="text" name="cost" id="textfield4" value="<?php echo $cost ; ?>"/></td>
              </tr>
             <tr>
              <td>&nbsp;</td>
              <td><input name="" type="submit"  value="submit"/></td>
              <td><div align="right">Total</div></td>
             
              
              
              
              <td><?php 
			 
			 $qty1=$_GET['qty'];
			$cost1=$_GET['cost'];
			$total=$qty1 * $cost1;
			 ?>
 <input type="text" name="textfield5" id="textfield5"  onfocus='"<?php echo $total; ?>" ' /></td>
             </tr></form>
             
	          </table><form id="form" method="post" name="form2">
 
	          </form>
	      </div>
	  </div>
	  <div id="footer"><br />
  <div align="center">
   
    </div>
	</div>
    </div>
</body>
</html>

Thanks in Advance...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.