Jump to content

Passing Values Drop Down/TextBox & Calculations


HuntinRabbits

Recommended Posts

Working on updating some old code so that when province/state is choosen, will pull the corresponding hst, gst percent values and shipping cost assigned to each one.

 

1.  There is an SQL table called state.  Holds fields called id, name, hst, gst and shipping.

 

2.  On the web page, a person can select the province of their choice via a drop down box.  This is how this works:

 

<select name="state_id" style="width:200px;">

<option>-----</option>

<?

foreach($states as $state) {

$selected = "";

if ($state->id == $state_id) $selected = " selected";

?>

<option value="<?=$state->id?>" selected="selected" <?=$selected?>><?=$state->name?></option>

<?

}

?>

</select>

 

-- > This works fine.  No problems.  However, keep reading:

 

-- > On the page I have the following text boxes:

 

- textfield called subtotal.

- textfield called hst.

- textfield called shipping.

- textfield called gst.

- textfield called grand_total.

 

I CANNOT figure out an onChange function or an event maybe even using an array so when the combo box changes province/state name, it will go to corresponding information and populate the textboxes.

 

(Ultimately, I want to pull the .13 or .05 % tax rates from the table so I can do a function that calculates subtotal, gst, hst, shipping and returns it to a grand_total field).

 

I have searched PHPFreaks.com and can not find something I understand on how to do this  Anyone have references to a help topic on this site that might explain how to select and pass values better?  Suggestions on how to go about this or set up?

 

Thanks!

Hi

 

Seems to be a Javascript bit of coding that is required.

 

If the number of states are limited (ie, not worldwide) then store the details in a javascript array, and use an on change event on the drop down list box to populate form input fields with the appropriate values from the array.

 

Down side is that it makes it reliant on Javascript.

 

All the best

 

Keith

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.