
gkornbluth
Veteran
Dec 13, 2011, 4:57 AM
Post #1 of 3
(354 views)
Shortcut
|
|
Javascript Problem
|
Can't Post
|
|
I've inherited a Javascript function that does tax calculation based on the State value entered in form a field.
function onchangestate(type){ if(type=='FL'){ tax=total * 0.06; total=total + tax; } else{ total=total ; } $('#totalcost').html('$' + total); } The field code is:
<select id="state" name="state" onChange="javascript:onchangestate(this.value)"> <option value="" selected="selected">Select</option> <option id="USA-AL" value="AL" >Alabama (AL)</option> ...more state options... <option id="USA-FL" value="FL" >Florida (FL)</option> <option id="USA-WY" value="WY">Wyoming (WY)</option> ...more state options... </select> This all works fine when the State value (FL or not FL) is selected from the list of options. I modified the field code to pull the state value from a user record instead of entering it manually with:
<input type="text" name="state" id="state" onChange="javascript:onchangestate(this.value)" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" > The state field now populates from the user record, but I'm guessing that since there are no products selected before field is populated, the function is not called at the appropriate time and I can’t get the tax calculation to work. Can someone help? Thanks, Jerry Kornbluth
|