Javascript Problem

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 13, 2011   (RSS)

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
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Jason] Javascript Problem

I changed it because I only wanted the value that was pulled from the current user record. I'll try your approach.

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php