I have the following code…
var min_val = [{"id":"driverDOA","value":date_of_accident},etc etc...];//put validation elements in an array
for (var i=0;i<min_val.length;i++)//loop through each element if array
{
var object = min_val[i];
if(object.value == "" || object.value == null)//if element is null or empty then execute code
{
document.getElementById(object.id).parentNode.innerHTML += '<div class="prompt accident">*</div>';
document.getElementById('accident-tab').innerHTML += '<div class="prompt accident">*</div>';
return false;
}
else
{
$('.prompt accident').remove();
sendAjaxRequest();
}
}
basically,I’m validating a form by storing the elements required in an array. I then loop through the array and check for any empty values. If the user has left a value then an asterisk is shown next to that element and on the tab for that section.
Once the user has filled in all of the marked form elements then the code removes the asterisks and send an Ajax request.
However at the moment once an empty element has been found it displays the asterisk for that and stops.
What i need is for it to loop through the entire array each time and display all asterisks. I have a feeling that this will be remarkably simple but have been unable to find anything or figure it out.
Any help would be appreciated
1 Answer