JSFiddle - React, Tailwind, and code Playground
by SchmalzyB
HTML
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<div class='form-group'>
<div class='col-md-5 col-md-offset-1 col-sm-6'>
<div class='input-group app-input'>
<input type='text' class='form-control' id='p_address' placeholder='Your Current Address'>
<span class='input-group-addon'><span class='glyphicon glyphicon-home'></span></span>
</div>
</div>
</div>
<div class='form-group app-input-no-group'>
<div class='col-md-5 col-md-offset-1 col-sm-6'>
<input type='text' class='form-control' id='p_address2' placeholder='Current Address Line 2'>
</div>
</div>
<div class='form-group app-input-no-group'>
<div class='col-md-3 col-md-offset-1 col-sm-4'>
<input type='text' class='form-control' id='p_city' placeholder='Your Current City'>
</div>
</div>
<div class='form-group app-input-no-group'>
<div class='col-md-3 col-md-offset-1 col-sm-4'>
<select class='form-control' id='p_state'>
<option value="" selected>Your Current State</option>
<? include $up_level.'inc/body/extras/state_list_options.php';?>
</select>
</div>
</div>
<div class='form-group app-input-no-group'>
<div class='col-md-3 col-md-offset-1 col-sm-4'>
<input type='text' class='form-control' id='p_zip' placeholder='Your Current Zip'>
</div>
</div>
<div class='form-group'>
<div class='col-md-5...
JavaScript
$(document).ready(function(){
//check if the mailing address checkbox is checked
//if so then we will fill the mailing address in with the information from current address then hide all the mailing address fields
//else clear the mailing address fields and show them again
//set variables
var p_values = ['p_address', 'p_address2', 'p_city', 'p_state', 'p_zip'];
var m_values = ['m_address', 'm_address2', 'm_city', 'm_state', 'm_zip'];
$("#mailing_address").change(function(){
if(this.checked){
//if checked get the values from the current address fields
for(var i = 0; i < p_values.length; i++){
$('#'+m_values[i]+'').val($('#'+p_values[i]+'').val());
$('#'+m_values[i]+'').attr('disabled', 'disabled');
}
}
else{
//this is the part that is failing
for(var i = 0; i < p_values.length; i++){
$('#'+m_values[i]+'').val("");
$('#'+m_values[i]+'').removeAttr('disabled');
}
}
});
});