I have a problem repopulating a set of checkboxes after an unsuccessful form validation returns the user back to the same form. Dropdown menus and text inputs could be repopulat
I tried all the solutions here none worked. So i collected all the data, packed it into an array, then use a loop to check if the values in the array match the value of the selected box, if so change the checked attribute to checked.
Here is the html code:
Here is the javascript code in a function
(function(){
var tag_string = '',
tags = tag_string.split(', ');
boxes = document.getElementsByClassName('tags');
for(i = 0; i< boxes.length;i++ ){
if(tags.toString().includes(boxes[i].value)){
boxes[i].checked = "checked";
}
}
})();