lundi 9 mai 2022

how to get multiple checkbox value in edit form?

So, I have an edit form in that I have two checkboxes and i can store the data of both the checkboxes as comma separated in database and display it on JSP page but when I click on edit in my JSP page it redirects to the form with all the fields populated except the checkboxes now if only one of the checkboxes is selected i am able to get that value in edit but not when both of them are selected.

Can someone Please help regarding this issue ??

I'll add what i have tried so far.

Checkboxes using Semantic UI


    <div class = "error_placement_checkbox">
        <div align = "center" class="ui inverted form" id = "idcheckbox">
            <div align = "center" class=" inline required fields">
                <label> Product Availability </label>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type = "checkbox" name = "p_act1" value = "In Stock" >
                            <label> In Stock </label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type = "checkbox" name = "p_act2" value = "Out Of Stock" >
                                <label> Out Of Stock </label>
                        </div>
                    </div>
            </div>
        </div>
    </div>

Jquery for retrieving first checkbox value only


        $(document).ready(function() {      
            $('input[name="p_act1"]').each(function(index){     
                if ($(this).val() == "<c:out value = '${product.p_act}' />")            
                ($(this).prop('checked' , true));
            });
        });

Jquery for retrieving second checkbox value only


        $(document).ready(function() {      
            $('input[name="p_act2"]').each(function(index){     
                if ($(this).val() == "<c:out value = '${product.p_act}' />")            
                ($(this).prop('checked' , true));
            });
        });

What I want is if user selects both the checkboxes, then in edit both of them should be selected. but now what's happening is if user has selected only one checkbox, only then in edit form I am getting one checkbox selected. but if user selects both checkboxes then in edit form both of them are not checked.




Aucun commentaire:

Enregistrer un commentaire