---- dataentry ----
type : integration #do not change this line
systems : FoxyCart #the system(s) that the integration is for, separated with commas if more than one
name : multiship_jquery_070+ #the name of the integration
description : (FC 0.7.0+) jQuery to automatically create a select box ("drop down") with previously entered ship-to addresses, with showing/hiding of the "New recipient" field.
tags : multiship #tags, separated by commas. don't include the "system" here.
date_dt : 2011-06-20 #the date in YYYY-MM-DD format
version : 2.3 #if you have a version for your code, enter it here
FC version : 070+
developer_url : http://www.foxycart.com #if you'd like a link back to your site, stick it here
----
====== multiship javascript ======
//**Please note:**//
The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.
===== Description =====
Quickly and easily add multiple ship-to addresses to your FoxyCart site by including a single javascript file and adding a few classes to your "add to cart" forms. It looks something like this:
| {{:integration:misc:multiship.javascript.01.png|}} | {{:integration:misc:multiship.javascript.02.png|}} | {{:integration:misc:multiship.javascript.03.png|}} |
| {{:integration:misc:multiship.javascript.04.png|}} | {{:integration:misc:multiship.javascript.05.png|}} | Multiship achieved! |
This script
- checks for the existence of a shipto cookie;
- displays a select box ("drop down") if there are any previously set ship-to recipients in the cookie;
- displays a "new recipient" input field if you choose "Add a new recipient..." in the select box;
- sets the select box to the previously selected shipto recipient;
- should be able to be used on pages with multiple "add to cart" forms.
===== Installation =====
- Copy the code below into a file named ''multiship.jquery.js'' and stick it somewhere on your server.
- Include the file in the ''
'' section of your template, //after// your ''foxycart.complete.js'' file.
- The script works by finding ''input'' and ''select'' elements inside divs with specific classes. You'll need to add, to your "add to cart" form...
- '''' inside a ''div.shipto_select'' (probably want to give that container ''div'' a ''display:none''; it gets shown with the javascript)
- '''' inside a ''div.shipto_name''
- It should look something like this:
- //PLEASE// make sure your code is valid. If your form is not valid you might get unexpected results. (Try [[http://users.skynet.be/mgueury/mozilla/|this for Firefox]] or [[http://validator.w3.org/|this]].)
- That should be it, but TEST. Then test some more.
- Finally, test again, and have your friends test.
- Report any issues on [[http://forum.foxycart.com|the forum]].
===== Requirements =====
* The foxycart.complete.js file, or jQuery by itself.
===== Code =====
/*
FoxyCart Multiship Javascript
v2.4
2013-03-02
INSTRUCTIONS:
http://wiki.foxycart.com/integration/foxycart/multiship_javascript_070
IMPORTANT:
If you're having problems with this script, MAKE SURE YOUR PAGE IS VALID.
Seriously, if your page is invalid (particularly with regard to forms
spanning beyond where they should, like starting in one
and going into
another) this code might have issues.
*/
function shipto_initialize() {
jQuery('div.shipto_select').show();
jQuery('div.shipto_name').hide();
jQuery('div.shipto_name input').val("");
}
// shipto_check checks for the existence of the shipto cookie
// returns an array of values, or false if no cookie found
function shipto_array() {
if (jQuery.cookie('shipto_names')) {
// Define the global shipto array
var shipto_array = jQuery.cookie('shipto_names').split('||');
shipto_array = unique(shipto_array);
shipto_array.sort();
return shipto_array;
} else {
return false;
}
}
function shipto_select() {
// Clear the shipto select boxes first
jQuery('div.shipto_select select').html('');
var shipto_options = '';
var shipto = shipto_array();
// alert('shipto: ' + shipto);
if (shipto) {
// alert('shipto is true');
jQuery.each(shipto, function(i, val){
// alert('starting the .each loop with: ' + i + ' = ' + val);
if (val != 'undefined' && val != 'null' && val != '' && val != 'Me') {
shipto_options += '