Created
August 1, 2013 14:43
-
-
Save rickycheers/6132058 to your computer and use it in GitHub Desktop.
Copy billing information into contact information for 2Dialog forms. *Add IDs to each HTML field, make them match the ones in the script. *Add a checkbox that will work as the control that will trigger the copy. <input id="fill_contact" style="vertical-align: middle" mce_style="vertical-align: middle" type="checkbox"> Same as Billing Information…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($, $$){ | |
$('fill_contact').observe('click', function(e) { | |
var name = $('billing_name').getValue() | |
, billing_address = $('billing_address').getValue() | |
, billing_city = $('billing_city').getValue() | |
, billing_state = $('billing_state').getValue() | |
, billing_zip = $('billing_zip').getValue() | |
, billing_phone = $('billing_phone').getValue() | |
, billing_email = $('billing_email').getValue(); | |
if( e.target.checked ){ | |
name = name == '' ? name : name.trim().split(/\s+/); | |
var first_name = name[0] || ''; | |
var last_name = name[1] || ''; | |
$('contact_first_name').setValue( first_name ); | |
$('contact_last_name').setValue( last_name ); | |
$('contact_email').setValue( billing_email ); | |
$('contact_address').setValue( billing_address ); | |
$('contact_city').setValue( billing_city ); | |
$('contact_state').setValue( billing_state ); | |
$('contact_zip').setValue( billing_zip ); | |
$('contact_phone').setValue( billing_phone ); | |
} else { | |
$('contact_first_name').setValue( '' ); | |
$('contact_last_name').setValue( '' ); | |
$('contact_email').setValue( '' ); | |
$('contact_address').setValue( '' ); | |
$('contact_city').setValue( '' ); | |
$('contact_state').setValue( '' ); | |
$('contact_zip').setValue( '' ); | |
$('contact_phone').setValue( '' ); | |
} | |
}); | |
})($, $$); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment