javascript in Checkit function?

General ShopSite user discussion

javascript in Checkit function?

Postby ryan@ddm » Tue Jun 10, 2008 8:39 pm

Using SS Pro 9.0.3.2

Per the suggestion here:
http://support.lexiconn.com/news/viewtopic.php?t=289

I have this code in the Javascript at start of checkit function field:

if (document.order.country.value != "US" && (document.order.shipping.value == "reg" || document.order.shipping.value == "sec")) {
alert("International customers cannot choose USA ONLY shipping options");
return(false);
}

*****************

Here is the relevant portion of the shopping cart page source code:
<table class="taxnship">
<tr><td class="taxnship_hdr" colspan="2">Choose a Shipping option</td></tr>
<tr><td class="taxnship"><input checked type=radio name="shipping" value="reg"> Standard UPS / USPS Shipping (2-5 business days)</td>
<td class="taxnship">($7.00)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="sec"> UPS 2nd Day Air </td>
<td class="taxnship">($18.60)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="nex"> UPS Next Day Air</td>
<td class="taxnship">($38.75)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="m3"> UPS 3 Day Select</td>
<td class="taxnship">($14.50)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="m4"> International - CANADA</td>
<td class="taxnship">($7.00)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="m5"> International - Rest of World - Standard</td>
<td class="taxnship">($7.00)</td>
</tr>
<tr><td class="taxnship"><input type=radio name="shipping" value="m6"> International - Rest of World - Express</td>
<td class="taxnship">($28.00)</td>
</tr>
</table>


However, it does not appear to be working. Can still select the shipping options in question, proceed to the next screen, and finalize the order. Can anyone spot what I may be doing wrong?
ryan@ddm
 
Posts: 47
Joined: Sat Aug 05, 2006 11:32 am

Postby Jim » Thu Jun 12, 2008 11:36 am

In my test store I copied the code from your post
Code: Select all
if (document.order.country.value != "US" && (document.order.shipping.value == "reg" || document.order.shipping.value == "sec")) {
alert("International customers cannot choose USA ONLY shipping options");
return(false);
}
and pasted it into the Commerce Setup > Order System > Shopping Cart > "Javascript added at start of built-in CheckIt function:" field and place and order. When I selected a non-US country and either the "reg" or "sec" shipping options I got the warning. When I selected another shipping option I didn't get the warning. When I selected United State then I did not get the warning with the first 2 shipping options.

So the code does work. Do you have the country field as a pulldown list or just a text box? It would need to be a pulldown list so the correct values for "US" can be determined. Do you have any other javascript added to the CheckIt function? Are you using the same field to input the javascript or did you add it directly to your template?
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Postby ryan@ddm » Thu Jun 12, 2008 12:23 pm

Issue now resolved. I didn't look closely enough to notice that the code in question was only suitable for dropdowns - a revised version which works for both dropdowns and radio buttons is:

if (document.order.shipping[0].type == "radio") {
for (var i=0; i < document.order.shipping.length; i++)
{
if (document.order.shipping[i].checked)
{
var rad_val = document.order.shipping[i].value;
}
}
}
else {
var rad_val = document.order.shipping.value;
}

if (document.order.country.value != "US" && (rad_val == "ZZZ" || rad_val == "YYY")) {
alert("International customers cannot choose USA ONLY shipping options");
return(false);
ryan@ddm
 
Posts: 47
Joined: Sat Aug 05, 2006 11:32 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 88 guests