I have a question about JQuery and While statements. I am pretty new to coding and one of my tasks is to check if there are any empty inputs when a user tries to submit a value, and return an alert. I first started by using if statements, and saw that only the first if statement would be read when I clicked on the submission button. I tried to implement a while loop to continuously loop through all of the statements until all sections were filled out, but I am not sure if I am going about this the right way.
I am not sure what to put in the while loop because I know it should be true, but true to some value. Any help would be appreciated!
let assetInfo = {
asset_tag_no: $(`#asset_tag_no${i}`).val(),
manufacturer: $(`#manufacturer_serial_no${i}`).val(),
descriptions: $(`#description${i}`).val(),
costs: $(`#cost${i}`).val(),
po_no: $(`#p.o._no${i}`).val(),
department_division_head: $(`#department_division_head${i}`).val(),
}
// Check for Empty Inputs and Enforce Users to Fill out Fields
$('#submit').click(function(){
while (assetInfo = true) {
if (assetInfo.asset_tag_no == '') continue;{
alert('Asset Tag Number can not be left blank');
}
if (manufacturer == '') continue; {
alert('Manufacturer Serial Number can not be left blank');
}
if (descriptions == '') continue;{
alert('The Description can not be left blank');
}
if (costs == '') continue;{
alert('The Cost can not be left blank');
}
if (po_no == '') continue;{
alert('The P.O Number/ Document Number can not be left blank');
}
if (department_division_head == '') continue;{
alert('The Remarks can not be left blank');
}
else{
alert('Submission Accepted');
break;
}
}
return assetInfo;
});