Jump to content

Need to Apply a formula for a text box in my form! not working


saravanataee

Recommended Posts

Hi there,

 

Following is the code of mine where i want the textbox named t8 to be loaded based on the value of combo named 'subcat3' , textbox name 'MRP', and textbox named 't7'.

 

The real formula is as applied in the form

 

this.t8.value=this.t8.value*subcat3*MRP-(MRP*t8/100)

 

i tried to apply the above formula but it doesnot load anything.!!

 

Dont know what prob..

 

Can anyone help me!!

 

Thanks

 


<?php

mysql_connect('localhost', 'root', '');
mysql_select_db('inventorydb');
?>

<?php

require "config.php"; 
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Purchase Order Form</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language="javascript">
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='po.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 

self.location='po.php?cat=' + val + '&cat3=' + val2 ;
}

</script>
</head>

<body>
<h1>Place an Order</h1>
<?php


///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT itemname,item_id FROM item order by itemname"); 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
if(isset($_GET['cat'])) {
$cat=$_GET['cat']; // This line is added to take care if your global variable is off
}
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT packingname,packing_id FROM packing where item_id=$cat order by packingname"); 
}else{$quer=mysql_query("SELECT DISTINCT packingname,packing_id FROM packing order by packingname"); } 
////////// end of query for second subcategory drop down list box ///////////////////////////


/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
if(isset($_GET['cat3'])) {
$cat3=$_GET['cat3']; // This line is added to take care if your global variable is off
}
else
{
$cat3 = "";
}
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT sizename FROM size where packing_id=$cat3 order by sizename"); 
}else{$quer3=mysql_query("SELECT DISTINCT sizename FROM size order by sizename"); } 
////////// end of query for third subcategory drop down list box ///////////////////////////


?>
<form method=post name=f1 action=''>

<table border='1' >

               <tr>
                       <td><label for="t1">Item</label></td>
                       <td><label for="t2">Quantity</label></td>
<td><label for="t2">Packing</label></td>
                       <td><label for="t2">Quantity in NO</label></td>
                       <td><label for="t2">MRP/RATE</label></td>
                       <td><label for="t2">Discount</label></td>
                       <td><label for="t2">Amount</label></td>





               </tr>
               <tr> <td> 
<?php
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['item_id']==@$cat){echo "<option selected value='$noticia2[item_id]'>$noticia2[itemname]</option>"."<BR>";}
else{echo  "<option value='$noticia2[item_id]'>$noticia2[itemname]</option>";}
}
echo "</select>";

?>
</td>

<td><input name="t3" id="t3" size="10" value=""></td>
<td>
<?php
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) { 
if($noticia['packing_id']==@$cat3){echo "<option selected value='$noticia[packing_id]'>$noticia[packingname]</option>"."<BR>";}
else{echo  "<option value='$noticia[packing_id]'>$noticia[packingname]</option>";}
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////
?>
</td>

<td>
<?php


//////////        Starting of third drop downlist /////////
echo "<select name='subcat3' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) { 
echo  "<option value='$noticia[sizename]'>$noticia[sizename]</option>";

//echo  "<input type='text' name='' value='$noticia[sizename]'/>";
}
echo "</select>";
//////////////////  This will end the third drop down list ///////////

?>
</td>
<td><input name="MRP" id="t7" size="10"  value=""></td>
<td><input name="t7" id="t8" size="10" placeholder="40%" value=""></td>
<td><input name="t8" id="t8" size="10" onchange="this.t8.value=this.t8.value*subcat3*MRP-(MRP*t8/100)" value=""></td>



</tr>
<tr>
<td></td><td></td><td></td><td></td>     
<td><input type="submit" name="submit" value="Place Order"></td>
                       <td><input type="reset" name="submit1" value="Reset"></td>
<td></td> </tr>

</body>

</html>

<?php
if(isset($_POST['submit']))
     {          


                                       $item=$_POST['cat'] ;
                                       $qty= $_POST['t3'] ; 
                                       $pack= $_POST['subcat'] ; 
                                       $qtyno= $_POST['subcat3'] ; 
                                       $mrp= $_POST['MRP'] ; 
                                       $dis= $_POST['t7'] ; 
                                       $amt= $_POST['t8'] ; 






              $query=  mysql_query("INSERT INTO `po`(Item,Quantity,Packing, QuantityNO, MRP, Discount, Amount) VALUES ('$item','$qty','$pack','$qtyno','$mrp','$dis','$amt')"); 
                if(!$query)
{
die('Query Failed with exception'.mysql_error());
}
}
?>

Link to comment
Share on other sites

I'd love to know what debugging steps you've taken so far?

 

That said you need to learn how to correctly select a form.

 

form = document.forms["TheNameOfMyForm"];

 

Why have you got an HTML 3.2 DOCTYPE as well? Out of curiosity.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.