Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added JS function to clone prims to mailing address fields

  • Loading branch information...
commit a3184530824d650d9133d21a424137eb6b5de3cd 1 parent 10256eb
@cinman authored
Showing with 30 additions and 18 deletions.
  1. +24 −16 js/plugins.js
  2. +6 −2 templates/index.html
View
40 js/plugins.js
@@ -20,19 +20,27 @@ $("#registerForm").validate();
// Duplicate Primary Address into Mailing Address
- $("input#copyaddress").click(function(){
- if ($("input#copyaddress").is(':checked'))
- {
- // Checked, copy values
- $("input#m-street-1").val($("input#p-street-1").val());
- $("input#m-street-1").val($("input#p-street-1").val());
- // $("input#shipping-phone").val($("input#phone").val());
- }
- /* else
- {
- // Clear on uncheck
- $("input#shipping-email").val("");
- $("input#shipping-name").val("");
- $("input#shipping-phone").val("");
- } */
- });
+$("input#copyaddress").click(function(){
+ var pstate = $('#p-state option:selected').val();
+ if ($("input#copyaddress").is(':checked')){
+ // Checked, copy values
+ $("input#m-street-1").val($("input#p-street-1").val()).attr('disabled', 'disabled');
+ $("input#m-street-2").val($("input#p-street-2").val()).attr('disabled', 'disabled');
+ $("input#m-city") .val($("input#p-city") .val()).attr('disabled', 'disabled');
+ $("input#m-state") .val($("input#p-state") .val()).attr('disabled', 'disabled');
+ $("input#m-zip") .val($("input#p-zip") .val()).attr('disabled', 'disabled');
+ $('#m-state option[value=' + pstate + ']') .attr('selected','selected');
+ $('#m-state') .attr('disabled', 'disabled');
+
+ }
+ else
+ {
+ // Remove Disabled Attribute
+ $("input#m-street-1").val($("input#p-street-1").val()).removeAttr('disabled');
+ $("input#m-street-2").val($("input#p-street-2").val()).removeAttr('disabled');
+ $("input#m-city") .val($("input#p-city") .val()).removeAttr('disabled');
+ $("input#m-state") .val($("input#p-state") .val()).removeAttr('disabled');
+ $("input#m-zip") .val($("input#p-zip") .val()).removeAttr('disabled');
+ $('#m-state') .removeAttr('disabled');
+ }
+});
View
8 templates/index.html
@@ -132,11 +132,11 @@
<tr>
<td>
<label>Street Line 2:</label>
- <input type="text" name="" id="" tabindex="13">
+ <input type="text" name="p-street-2" id="p-street-2" tabindex="13">
</td>
<td>
<label>Street Line 2:</label>
- <input type="text" name="" id="" tabindex="19">
+ <input type="text" name="m-street-2" id="m-street-2" tabindex="19">
</td>
</tr>
<tr>
@@ -174,12 +174,16 @@
<label>State:<span class="required">*</span></label>
<select name="p-state" id="p-state" tabindex="15" class="required">
<option value="">--Select--</option>
+ <option value="MI">Michigan</option>
+ <option value="OH">Ohio</option>
</select>
</td>
<td>
<label>State:<span class="required">*</span></label>
<select name="m-state" id="m-state" tabindex="21" class="required">
<option value="">--Select--</option>
+ <option value="MI">Michigan</option>
+ <option value="OH">Ohio</option>
</select>
</td>
</tr>

4 comments on commit a318453

@benbabics
Collaborator

Pretty cool. Though, here is a quick script that will allow you to duplicate physical address values:
http://jsfiddle.net/bbabics/R4Tdf/

Just use the convention:
<input id="primary_fieldname">
and
<input id="secondary_fieldname">

@cinman
Owner

Always one up-in' me huh - ya punk :)

@benbabics
Collaborator
@cinman
Owner

I know man. I appreciate it.

Please sign in to comment.
Something went wrong with that request. Please try again.