Jump to content

wangtian

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

wangtian's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. any one can help me on this code? the problem on this code is that it only give me the result of the last mutification (chassis.value * Quantity1.value). I want to get the result of motherboard.value * Quantity + Chassis.value * quantity1. anyone know how to fix this problem. I appreciate it. function calculate(){ document.calcform.total.value = parseFloat(document.calcform.Motherboard.value || 0) * parseFloat(document.calcform.Quantity.value || 0) + parseFloat(document.calcform.Chassis.value || 0) * parseFloat(document.calcform.Quantity1.value || 0) } here are the code on my page. <style type = "text/css"> .SelectClass { font-size: 15px; } table { font-size: .9em; border: 3px groove; padding: 0px; background-color: #dddddd; } .mycss { font-weight:normal;font-style:italic;color:#000000;letter-spacing:1pt;word-spacing:2pt;font-size:36px;text-align:left;font-family:courier new, courier, monospace;line-height:1; } </style> <script LANGUAGE="JavaScript"> function dp(price) { string = "" + price; number = string.length - string.indexOf('.'); if (string.indexOf('.') == -1) return string + '.00'; if (number == 1) return string + '00'; if (number == 2) return string + '0'; if (number > 3) return string.substring(0,string.length-number+3); return string; } function calculate(){ document.calcform.total.value =dp(parseFloat(document.calcform.Motherboard.value|| 1)* parseFloat(document.calcform.Quantity.value || 1)+parseFloat(document.calcform.Chassis.value|| 0)* parseFloat(document.calcform.Quantity1.value || 0)) } </script> </head> <body onload="calculate"> <div class="mycss"><center>Order List</center></div><br /> <center> <form name="calcform" method="post" action="test2.php"> <table border="0" width="800"> <tr> <td align="right" colspan="2"> <font size="6">$</font><input name="total" style="border:0px solid #000000; background-color:#E6FBF4; font-size: 25.5px;" type="text" value="0.00" ONCHANGE="calculate()"/> </td></tr> <tr> <td><font size="+1"> Product Name</font> </td> <td><font size="+1">Quantity</font></td></tr> <td colspan="2"> <?php mysql_connect("mysql1.000webhost.com", "a4202648_wang", "wang2011") or die(mysql_error()); mysql_select_db("a4202648_wang") or die(mysql_error()); echo "<table width='100%'>"; echo "<tr><td align='left' width='90%'>"; $result = mysql_query("SELECT Motherboard_Part_Number, Motherboard_Name, Motherboard_Price FROM Motherboard ") or die(mysql_error()); echo '<select id="Motherboard" class="SelectClass" name="Motherboard" ONCHANGE="calculate()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Motherboard" value= ',$row['Motherboard_Price'],'>',$row['Motherboard_Part_Number'],' ',$row['Motherboard_Name'],' $',$row['Motherboard_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td align='right' width='10%'>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select id="Quantity" class="SelectClass" name="Quantity" Value="Quantity" ONCHANGE="calculate()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "<tr><td align='left' width='90%'>"; $result = mysql_query("SELECT Chassis_Part_Number, Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select id="Chassis" class="SelectClass" name="Chassis" ONCHANGE="calculate()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis" value= ',$row['Chassis_Price'],'>',$row['Chassis_Part_Number'],' ',$row['Chassis_Name'],' $',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td align='right' width='10%'>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select id="Quantity" class="SelectClass" name="Quantity1" Value="Quantity" ONCHANGE="calculate()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> </td> </tr> <tr><td colspan="2"><input type="submit" /></td></tr> </table> </form> </center> </body> </html> [attachment deleted by admin]
  2. hi, I want to calculate selectbox value in a form. for example: item price * Quantity. it's works fine if it only have one calculation in the form. function calculate(){document.calcform.total.value =(document.calcform.Chassis.value)*(document.calcform.Quantity.value) } howerver, when when I have more than one calculation, it gives me "NaN.00" here is the function calculate(){ document.calcform.total.value = (document.calcform.Motherboard.value)*(document.calcform.Quantity.value)+(document.calcform.Chassis.value)*(document.calcform.Quantity1.value) } I also posted a picture about the result. Anyone can help me to fix it? I appreciate it. here is all my code on the page: <html> <head> <title> </title> <style type = "text/css"> .SelectClass { font-size: 15px; } table { font-size: .9em; border: 3px groove; padding: 0px; background-color: #dddddd; } .mycss { font-weight:normal;font-style:italic;color:#000000;letter-spacing:1pt;word-spacing:2pt;font-size:36px;text-align:left;font-family:courier new, courier, monospace;line-height:1; } </style> <script LANGUAGE="JavaScript"> function dp(price) { string = "" + price; number = string.length - string.indexOf('.'); if (string.indexOf('.') == -1) return string + '.00'; if (number == 1) return string + '00'; if (number == 2) return string + '0'; if (number > 3) return string.substring(0,string.length-number+3); return string; } function calculate(){ document.calcform.total.value = dp((document.calcform.Motherboard.value)*(document.calcform.Quantity.value)+(document.calcform.Chassis.value)*(document.calcform.Quantity1.value)) } </script> </head> <body onload="calculate"> <div class="mycss"><center>Order List</center></div><br /> <center> <form name="calcform" method="post" action="test2.php"> <table border="0" width="800"> <tr> <td align="right" colspan="2"> <font size="6">$</font><input name="total" style="border:0px solid #000000; background-color:#E6FBF4; font-size: 25.5px;" type="text" value="0.00" ONCHANGE="calculate()"/> </td></tr> <tr> <td><font size="+1"> Product Name</font> </td> <td><font size="+1">Quantity</font></td></tr> <td colspan="2"> <?php mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("a4202648_wang") or die(mysql_error()); echo "<table width='100%'>"; echo "<tr><td align='left' width='90%'>"; $result = mysql_query("SELECT Motherboard_Part_Number, Motherboard_Name, Motherboard_Price FROM Motherboard where Motherboard_Part_Number='MB-435ED-3'") or die(mysql_error()); echo '<select id="Motherboard" class="SelectClass" name="Motherboard" ONCHANGE="calculate()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Motherboard" value= ',$row['Motherboard_Price'],'>',$row['Motherboard_Part_Number'],' ',$row['Motherboard_Name'],' $',$row['Motherboard_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td align='right' width='10%'>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select id="Quantity" class="SelectClass" name="Quantity" Value="Quantity" ONCHANGE="calculate()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "<tr><td align='left' width='90%'>"; $result = mysql_query("SELECT Chassis_Part_Number, Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select id="Chassis" class="SelectClass" name="Chassis" ONCHANGE="calculate()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis" value= ',$row['Chassis_Price'],'>',$row['Chassis_Part_Number'],' ',$row['Chassis_Name'],' $',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td align='right' width='10%'>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select id="Quantity" class="SelectClass" name="Quantity1" Value="Quantity" ONCHANGE="calculate()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> </td> </tr> <tr><td colspan="2"><input type="submit" /></td></tr> </table> </form> </center> </body> </html> [attachment deleted by admin]
  3. someone can help me on this code? I appreicate it. I want to calculate the dropdown boxs values. the values that on the dropdown box are retrived from the mysql database. I want to have total price on the page without refresh. maybe you will be eassier to understand I am trying to say if you see my attached UI picture. here are the code; <code> <html> <head> <title> </title> <script type="text/javascript"> $('document').ready( function() { function change() { var quantity = $('#quantity').val(); var chassis = $('#chassis').val(); var sum = quantity * chassis; $('#the_sum').val(sum); } }); </script> </head> <body> <form action="" method="post"> <?php mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("a4202648_wang") or die(mysql_error()); echo "<table border='1'>"; echo "<tr><td>"; $result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select id="chassis" name="Chassis" onChange="change()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis" value=',$row['Chassis_Price'],'>',$row['Chassis_Name'],' ',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select id="quantity" name="Quantity" Value="Quantity" onChange="change()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option value=',$row['Number'],'>',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> <input type="text" value="" id="the_sum" /> <input type="submit" /> </form> </body> </html> </code> [attachment deleted by admin]
  4. that's true . I want to show the result of the multiply before the user submit the form, then display the invoice after sumbit the form . the problem now is I don't know how to code the calculation.
  5. hi. I am stuck on the dropdown box value calculation. anyone can help me on this problem ? I appreciate it. I have two dropdown boxes on my webpage, and the values that in the dropdown boxes are retrived from the mysql database. dropdown box "A" displays two differnt values, which are "Chassise_Name" and "Chassise_price", and The dropdown box "B" displays the quantity of the item. Dropdown box "A" Dropdown box "B" SuperServer 7036A-T(Black) $90 3 "Superserver 7036A-T(Black)" is retrieved from the Chassis_Name ; "$90" is retrieved from the chassis_Price; "3" is retrieved from the Quantity in other table. Question: how can I take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"? Here is my code: echo "<table border='1'>"; echo "<tr><td>"; $result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select name="Chassis" onChange="change()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis">',$row['Chassis_Name'],' ',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select name="Quantity" Value="Quantity" onChange="change()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option Name="Quantity">',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?>
×
×
  • 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.