Jump to content

calculate the value in two dropdown box without refresh


wangtian

Recommended Posts

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.