I have a form which contains dynamically created text input (they have the class serialNumber). Once text is entered into one of these inputs, the script below is meant to check the text and return the result into a dynamically created DIV (serialNumberSearchResults).
The code below will submit, however the posted serialNumber value is blank. I have been searching for a solution, however they all seem to require the use of a unique ID, which I can't do as the inputs and DIVs are dynamically generated.
<div name="serialNumberBox">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<thead>
<tr>
<td>Serial number</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="serialNumber" name="serialNumber[]" placeholder="enter serial number">
<div class="serialNumberSearchResults"></div></td>
</tr>
</tbody>
</table>
</div>
// check serial number
$(document).on('keyup', '.serialNumber', function () {
// wait 0.5 second before acting
delay(function() {
// submit the form
$.ajax({
type: 'POST',
url: 'assetProcess.php',
data: { serialNumber: $(this).val() },
success: function(response) {
if (response != undefined) {
$(this).closest('.serialNumberSearchResults').html(response);
}
},
error: function() {
$(this).closest('.serialNumberSearchResults').html('Error! Plese try again.');
}
});
return false;
}, 500);
});
<div>an "id" or a "class", not a "name".