Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript checkbox enable/disable

Ok this is very anoying, and it is probably very simple. I want to start my web page with disabled checkboxes, and after particlar line in listbox is selected to enable those boxes. So I put this in onload method

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

it start my page with disabled boxes, now i want do 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 goes in to the for loop, but it never enable those checkboxes. I cannot figure it why.

and this is html part, where i call enablecheckbox 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 actual checkboxes:

<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>
like image 366
Dejan Stuparic Avatar asked Mar 07 '11 01:03

Dejan Stuparic


1 Answers

Try instead:

    document.frmMain.checkgroup[i].disabled = false ;
like image 138
Edward Z. Yang Avatar answered Oct 05 '22 05:10

Edward Z. Yang