I'm trying to get the data of EACH row when a user has an email and put it in an array. So basically when the user clicks on the checkbox it enables the input field so they can enter an email. So far I am able to get the emails but I don't know how to get the data for each row ONLY for the users that have an email and the checkbox is still checked. For example if I select the first 2 users and enter an email I should get 2 elements in my array:
EXAMPLE:
Mike brown 3035607897 [email protected]
Mary Bruns 3035607233 [email protected]
Here's my code:
$(document).ready(function() {
$("#checkAll").change(function() {
$(".input_checkbox").prop('checked', $(this).prop("checked")).each(function() {
enable_disable_input(this);
});
});
function enable_disable_input(checkbox) {
var input_id = checkbox.id.replace('-checkbox', '-inputField');
$("#" + input_id).prop('disabled', !checkbox.checked);
}
$(".input_checkbox").change(function() {
enable_disable_input(this);
});
$(".input_checkbox").each(function() {
enable_disable_input(this);
});
/* Collecting data ONLY from users that have an email */
$("#myform").submit(function(event){
event.preventDefault();
$(".inputEmail").each(function(){
if($(this).val().length > 0){
var inputValue = $(this).val();
console.log(inputValue);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id = "myform">
<input type="checkbox" id="checkAll" />Select All
<br/>
<tr>
<td><input type="checkbox" id="0customer-name-checkbox" class="input_checkbox"></td>
<td>Mike</td>
<td>brown</td>
<td>3035607897</td>
<td><input type="email" name="name" id="0customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="1customer-name-checkbox" class="input_checkbox"></td>
<td>Mary</td>
<td>Bruns</td>
<td>3035607233</td>
<td><input type="email" name="email" id="1customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="2customer-name-checkbox" class="input_checkbox"></td>
<td>Lauren</td>
<td>White</td>
<td>3035634211</td>
<td><input type="email" name="email" id="2customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="3customer-name-checkbox" class="input_checkbox"></td>
<td>Tyler</td>
<td>Steven</td>
<td>3035236671</td>
<td><input type="email" name="email" id="3customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="4customer-name-checkbox" class="input_checkbox"></td>
<td>Carl</td>
<td>Douglas</td>
<td>3035227243</td>
<td><input type="email" name="email" id="4customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="5customer-name-checkbox" class="input_checkbox"></td>
<td>Peter</td>
<td>McClure</td>
<td>3035112239</td>
<td><input type="email" name="email" id="5customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<tr>
<td><input type="checkbox" id="6customer-name-checkbox" class="input_checkbox"></td>
<td>Liz</td>
<td>Prems</td>
<td>3035120075</td>
<td><input type="email" name="email" id="6customer-name-inputField" class = "inputEmail"/></td>
</tr>
<br/>
<input type="submit" value="Send"/>
</form>
Can someone tell me what I'm missing please?? Thanks a lot!