JS Actions Specific to Button Pressed

Questions and answers about ShopSite Custom Templates

JS Actions Specific to Button Pressed

Postby ajhauser » Tue Feb 14, 2012 11:23 pm

I have implemented a few custom shipping options. When the user clicks the "Continue to Checkout" button I need a chunk of javascript to run so I can show the user info based on their selection. For example, if they select "Local Delivery : $19.95" and their Delivery Password is incorrect, they need to receive an error alert, but I also need to STOP the main CheckIt script from proceeding to the next page "Billing Information". (This is the second "if" statement listed below. Even though I return a "false" the CheckIt moves to the next page. There must be a way to combine these and stop it from proceeding?). I looked at the ShopSite "Javascript added at start of built-in CheckIt function:" field, but even if we use this I'm not sure how to get the script to apply to only 1 button... and again, stop the entire script from proceeding... etc.

The site can be seen here without any JS additions yet: http://brotherscountrysupply.com/store/

My Javascript is working in a test file I have stored locally - aside from stopping the CheckIt script. I need to figure out how to stop it, and where to put this code so it only runs when "Continue to Checkout" is pressed.

Code: Select all
<script type="text/javascript" language="JavaScript">
   function TestFunction () {   
      var aj_get_delivery_method = document.getElementById("PasswordProtectedLocalDelivery");
      var user_delivery_selection = aj_get_delivery_method.options[aj_get_delivery_method.selectedIndex].text;
      var aj_local_password = "338goatsonfire";
      var user_input_password = document.getElementById("Local-Delivery-Password-Field").value;
      
         if (user_delivery_selection == "Local Delivery : $19.95" && user_input_password == aj_local_password)
            {
            alert("Thank you for using our Local Delivery service. Please call the store to follow up with your order. Orders placed during the week may not necessarily ship until the following Friday. Thanks!");
            }
         
         if (user_delivery_selection == "Local Delivery : $19.95" && user_input_password != aj_local_password)
            {
            alert("You have selected Local Delivery but your password appears to be incorrect or out of date. Please try again or contact the store if problems persist. If you have not yet signed up for our Local Delivery Service, click the link under the password input area to begin the process.");
            return false;
            }
            
         if (user_delivery_selection == "Cash & Carry : $0.00")
            {
            alert("Please contact the store after you complete your order to discuss available pickup times. Thanks!");
            }
            
            
   }
</script>


There is one other thing.
In order for my JS to work, I need to add an "id" attribute to the shipping select tag.

So change this:
Code: Select all
<td class="taxnship">Shipping <select class="ship" name="shipping">...

Into this:
Code: Select all
<td class="taxnship">Shipping <select class="ship" name="shipping" id="PasswordProtectedLocalDelivery">...


Any help is really appreciated. This project is so close to completion...
Thanks.
Website Design, Website Development, eCommerce and Hosting
ajhauser
 
Posts: 84
Joined: Tue Dec 06, 2011 4:18 pm
Location: Earlville - the land of Earls

Return to Custom Template Questions

Who is online

Users browsing this forum: Google [Bot] and 1 guest