Page 1 of 1

Do i need to use AJAX for this?

Posted: Fri Jun 12, 2009 5:29 pm
by luke4868

Code: Select all

<tr>
        <td><input name="product1" type="text" id="product1" size="55" />        </td>
        <td><select name="vat" id="vat">
          <option value="yes">Yes</option>
          <option value="no" selected="selected">No</option>
        </select>
</td>
        <td><div align="center">
          <input name="quantity1" type="text" id="quantity1" size="6" />
        </div></td>
        <td><input name="price1" type="text" id="price1" size="13" /></td>
        <td><input name="subtotal" type="text" id="subtotal" value="[b]<?php echo $price1 * $quantity1 ?>[/b]" size="14" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
Ignore the table structure, not important.

That aside, I need to be able to type the price in, and the quantity, then as soon as thats done, the subtotal to appear. Ive also tried onclick, onselect etc and they didnt work. the variables are called beforehand which are simply

Code: Select all

<?php 
 
$price1 = $_POST['price1'];
$price2 = $_POST['price2'];
$price3 = $_POST['price3'];
$price4 = $_POST['price4'];
$price5 = $_POST['price5'];
$price6 = $_POST['price6'];
$price7 = $_POST['price7'];
$price8 = $_POST['price8'];
$price9 = $_POST['price9'];
$price10 = $_POST['price10'];
$price11 = $_POST['price11'];
$price12 = $_POST['price12'];
$price13 = $_POST['price13'];
$price14 = $_POST['price14'];
$price15 = $_POST['price15'];
 
$quantity1 = $_POST['quantity1'];
$quantity2 = $_POST['quantity2'];
$quantity3 = $_POST['quantity3'];
$quantity4 = $_POST['quantity4'];
$quantity5 = $_POST['quantity5'];
$quantity6 = $_POST['quantity6'];
$quantity7 = $_POST['quantity7'];
$quantity8 = $_POST['quantity8'];
$quantity9 = $_POST['quantity9'];
$quantity10 = $_POST['quantity10'];
$quantity11 = $_POST['quantity11'];
$quantity12 = $_POST['quantity12'];
$quantity13 = $_POST['quantity13'];
$quantity14 = $_POST['quantity14'];
$quantity15 = $_POST['quantity15'];
 
?>
I have the feeling im doing something really stupid here, and probably am. Buts its late at night and i cant figure it out, please help. You can also see the page at http://www.1clickclothing.co.uk/manual.php

Re: Do i need to use AJAX for this?

Posted: Fri Jun 12, 2009 6:52 pm
by requinix
luke4868 wrote:then as soon as thats done
As soon as what's done? When they stop typing? When the form gets submitted?

For the former you need JavaScript. Set an onchange event handler for both quantity and price text boxes and do the math there instead. Like

Code: Select all

<input name="quantity1" type="text" id="quantity1" size="6" onchange="this.form.subtotal1.value=this.value*this.form.price1.value;" />
Then a similar one for price1.

Remember to calculate the subtotals in your PHP too - don't trust the form to have the right values.

Re: Do i need to use AJAX for this?

Posted: Fri Jun 12, 2009 6:56 pm
by luke4868
Hey, thanks for helping.

In regards to 'when thats done' I mean as soon as the quantity and price are both entered, they are blank by default. I'll have a go at that javascript in the morning, thanks.