I have this code for passing values from multiple inputs to other inputs and it's working well. The problem is that I'm saving the value of one input inside an object, but if I do this process, I'll have to add 8 values inside the object and inside conditions statements.
How can I add it to my code and make it works?
How I can get the values of the 8 inputs and pass it to other 8 inputs.
This is my JS code:
var data = {
first_name: $('#first_name'),
}
if ($('#checkbox').is(':checked')) {
$('#check_name').val(data.first_name.val());
}
$('#checkbox').change(function() {
if ($('#checkbox').is(':checked')) {
$('#check_firstname').val(data.first_name.val());
} else {
$('#check_name').val('');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
This is my view
//These are which I'm getting the values
<form class="mt-4 mb-4 ml-4 ">
<div class="row">
<div class="col">
<label for=""><h6>First name <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked" id="first_name">
</div>
<div class="col">
<label for=""><h6>Last name <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>Street Address <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
<div class="col">
<label for=""><h6>Street Address 2</h6></label>
<input type="text" class="form-control checked">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>Country <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
<div class="col">
<label for=""><h6>City <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>State/Province <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
<div class="col">
<label for=""><h6>Phone <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control checked">
</div>
</div>
</form>
<!--These are the inputs which I'm passing the values-->
<form class="mt-4 mb-4 ml-4 ">
<div class="row">
<div class="col">
<label for=""><h6>First name <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check" id="check_name">
</div>
<div class="col">
<label for=""><h6>Last name <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>Street Address <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
<div class="col">
<label for=""><h6>Street Address 2</h6></label>
<input type="text" class="form-control check">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>Country <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
<div class="col">
<label for=""><h6>City <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
</div>
<div class="row mt-4">
<div class="col">
<label for=""><h6>State/Province <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
<div class="col">
<label for=""><h6>Phone <span class="text-danger">*</span></h6></label>
<input type="text" class="form-control check">
</div>
</div>
</form>