Jump to content

[SOLVED] PHP and Javascript help


spires

Recommended Posts

Hi.

 

I am trying to pull information out of 2 of my database's, place it in to 2 seperate dropdown menus then use javascript to multiply the results.

 

Please See:

http://www.businessmobiles.com/comcalc/test.php

 

The javascript works with the php, But once the dropdown is placed inside of php then the form has some strange errors.

 

- In the example (link above), if you select 340 and 450 then submit the form, you will see that it works. However, if you select 'test 2' and 'test 1' from the drop downs, it does not work. Even though the values of 'test 2' and 'test 1' are '2 and 1'.

 

It seems that once inside the php the form is reading from the string not the value???

 

Any help please, I'm completely stuck

Thank

 

<?PHP
session_start();
include("../dbconnect.php");
include("../Library/head.php");

$usName = $_SESSION["usName"];

// Item
$item_sql = "SELECT * FROM csv_item";
$item_result = mysql_query($item_sql) or die ("query 2 failed".mysql_error());
$item_count = mysql_num_rows($item_result);

// Product
$product_sql = "SELECT * FROM csv_product";
$product_result = mysql_query($product_sql) or die ("query 2 failed".mysql_error());
$product_count = mysql_num_rows($product_result);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<script language="javascript">

		function getTotal()
		{
						var selectedPrice, selectedTariff, finalTotal;

						selectedPrice = document.form1.price.value;
						selectedTariff = document.form1.tariff.value;

						finalTotal = selectedPrice * selectedTariff;

						document.form1.total.value = finalTotal;
		}

</script>

<form name="form1">
<select name="price" onchange="this.style.backgroundColor = '#FFCCCC'">
<option value="1">add 1</option>
<option value="2">add 2</option>
<option value="3">add 3</option>
<option value="4">add 4</option>
<option value=""> </option>
<?PHP
while ($item_row = mysql_fetch_assoc($item_result)){
				$item_commission = $item_row['item_commission'];

				echo'
				<option vaule="'.$item_commission.'">'.$item_commission.'</option>
				<option vaule="2">test 2</option>';
}

?>
</select>
  
<select name="tariff" onchange="this.style.backgroundColor = '#FFCCCC'">
<?PHP
while ($product_row = mysql_fetch_assoc($product_result)){
				$product_trade = $product_row['product_trade'];

				echo'
				<option vaule="'.$product_trade.'">'.$product_trade.'</option>
				<option vaule="1">test 1</option>';
}

?>
</select>
<br>
<input name="total" type="text" size="14" />
<br>
<input type="button" value="add" onclick="getTotal()" /> 
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/155080-solved-php-and-javascript-help/
Share on other sites

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.