Repopulating checkboxes in Codeigniter after Unsuccessful Form Validation

前端 未结 9 767
梦毁少年i
梦毁少年i 2021-02-04 16:18

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

9条回答
  •  死守一世寂寞
    2021-02-04 16:40

    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";
            }
        }
    })();
    

提交回复
热议问题