Forum Moderators: open
I've got a typical selection field of countries and want to set the value of a text field with a shipping cost based upon a match to "USA" (If USA then x.00) or another amount for all others (Else y.yy)
Here's what I've got that is not working:
<script type="text/javascript">
function ctryCalc()
{
if (document.form1.country.value == "USA") {
document.form1.shippingcalc.value = "5.95";
}
else
{
document.form1.shippingcalc.value = "9.95";
}
}
</script>
The form's ID is "form1" and the field with the option list is "country" and the field to get the shipping result is "shippingcalc".
I could also grab the two shipping cost values from hidden fields.
Thanks
John
Easier to use the DOM.
<script type="text/javascript">
function ctryCalc() {
if (document.getElementById('country').value == "USA") {
document.getElementById('cost').value = "5.95";
} else {
document.getElementById('cost').value = "9.95";
}
}
</script>
<select id="country" name="country" onchange="if(this.value!= 0){ctryCalc()}">
<option value="0">Choose..</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
</select>
<input type="text" name="cost" id="cost" value="" />
Think that should work ok.
dc