function ship_stuff()
{
ship_me = document.getElementById("shipMethod").value;
alert(ship_me);
if("ship_me" == "priority2" )
{
document.getElementById("shippingChg").value = 3.20;
}
else if(ship_me == "priority3")
{
document.getElementById("shippingChg").value = 4.30 ;
}
else if(ship_me == "priority4")
{
document.getElementById("shippingChg").value = 5.40 ;
}
else if(ship_me == "overnight")
{
document.getElementById("shippingChg").value = 15.75 ;
}
else if(ship_me == "UPS")
{
document.getElementById("shippingChg").value = 15.00 ;
}
else (ship_me == "free")
{
document.getElementById("shippingChg").value = 0.00 ;
}
The HTML portion of the code:
<tr>
<th colspan="4" class="label">Shipping Method:
<select name="shipMethod" id="shipMethod" size="1">
<option value="">Choose a shipping method</option>
<option value="priority2">Priority mail $3.20 (4 items or less)</option>
<option value="priority3">Priority mail $4.30 (6 items or less)</option>
<option value="priority4">Priority mail $5.40 (8 items or less)</option>
<option value="overnight">Express $15.75 (4 items or less only)</option>
<option value="UPS">UPS - 2 day $15.00 (9 - 49 items)</option>
<option value="free">Free shipping (50+ items only)</option>
</select>
</th>
<td><input name="shippingChg" id="shippingChg" type="text" size="10" maxlength="60" value="" /></td>
</tr>
<tr>
My javascript loop is failing when I try and compare my variable to a string. It wont put the option value in to compare as a string. Any ideas how I can fix this?
Thanks for the help!
You’re missing an
ifin the final else clause. If you want it to always run, remove the conditional in parentheses.Also, try a mapping instead of the if/else chain: