Enable / disable javascript checkbox

Well, this is very unpleasant, and it is probably very simple. I want to launch my web page with the checkboxes disabled, and after the participant’s row in the list is selected in them, select these fields. So I put this in the onload method

onload = function () { for (i = 0; i < document.frmMain.checkgroup.length; i++){ document.frmMain.checkgroup[i].disabled = true ; } } 

it will launch my page with disabled blocks, now I want to enable them

 function enableCheckboxes(){ if (document.frmMain.Vrste[document.frmMain.Vrste.selectedIndex].value == "Sendvici i Rostilj"){ for(i=0;i<document.frmMain.checkgroup.length;i++){ document.frmMain.checkgroup[i].enabled = true; } } } 

it enters the for loop, but never includes these flags. I can’t understand why.

and this is the html part where I call the checkcheckbox function:

 <select name="Vrste" onChange="PopulatePodvrste(); enableCheckboxes();" size="8"> <option value="Pica">Pica</option> <option value="Barbarina domaca trpeza">Barbarina domaca trpeza</option> <option value="Slana Palacinka">Slana Palacinka</option> <option value="Slatka Palacinka">Slatka Palacinka</option> <option value="Sendvici i Rostilj">Rostilj i sendvici</option> <option value="Dobro jutro sa Barbarom">Dobro jutro sa Barbarom</option> <option value="Chicken Meni">Chicken Meni</option> <option value="Posebna Ponuda">Posebna Ponuda</option> <option value="Salate">Salate</option> </select> 

And finally, the actual flags:

 <input type="checkbox" name="checkgroup" >Susam</input><br> <input type="checkbox" name="checkgroup" >Cili</input><br> <input type="checkbox" name="checkgroup" >Tartar</input><br> <input type="checkbox" name="checkgroup" >Urnebes</input><br> <input type="checkbox" name="checkgroup" >Krastavac</input> 
+4
source share
2 answers

Try instead:

  document.frmMain.checkgroup[i].disabled = false ; 
+9
source

if I were to add a jquery library to your page, I would add:

 $(document).ready(function() { $("input[name='checkgroup']").attr("disabled", "disabled"); }) function enableCheckboxes() { $("input[name='checkgroup']").removeAttr("disabled"); } 

If you do not want to use jquery, just change the inclusion line:

 document.frmMain.checkgroup[i].disabled = false ; 
+1
source

Source: https://habr.com/ru/post/1342571/


All Articles