Web Hosting Talk







View Full Version : javascript PHP and HTML all in one..(help)


SharkBait
08-19-2005, 06:33 PM
Alight,

I have troubles finding places for help with javascript but here is the php code:



<?php // Load form with amount of items to be requested
$class = "one";
for($i=1; $i<=$num; $i++) {
if ($class == "one") {
$class = "two";
} else {
$class = "one";
}
echo "<tr>
<td class=\"{$class}\" width=\"5\">{$i}:</td>
<td class=\"{$class}\"><input type=\"text\" name=\"items[]\" size=\"20\" maxlength=\"50\" /></td>
<td class=\"{$class}\"><input type=\"text\" name=\"description[]\" size=\"30\" maxlength=\"50\" /></td>
<td class=\"{$class}\"><input type=\"text\" name=\"quant[]\" size=\"4\" onkeyup=\"get_total()\" /></td>
<td class=\"{$class}\"><input type=\"text\" name=\"cost[]\" size=\"10\" onkeyup=\"get_total()\" /></td>
<td class=\"{$class}\"><input type=\"text\" name=\"amount[]\" value=\"0.00\" size=\"10\" /></td>
</tr>";
}
?>



Now I have a javascript function declared in the <head> of the site
function get_total() {

x = document.forms.poform;
quant = x.quant.value;
cost = x.cost.value;
x = quant * cost;

return x.amount.value;

}

But because I can very the number of line items in my PHP script and put them into an array. I don't think javascript can pick off the value from the form properly and I am unsure how I can go about this.

What I am trying to do is when they enter a price and a quantity, the amount is updated. I could do this all PHP based and refresh the page, but thats just ugly and annoying.

Anyone have an idea how I can pass the value of quant[] cost[] and return it into amount[] in the form?

Cheers,

anon-e-mouse
08-20-2005, 12:22 AM
Moved to Programming Discussion as it looks to be better suited here.