Jump to content

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]

You have to use javascript to do calculations without page refreshes.  javascript is a language that exists inside your HTML document and is executed on the client's computer, not on your server.

 

-Dan

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.