lundi 27 août 2018

javascript disable checkbox when another checkbox is checked with same name

I'm trying to make a little quiz in my project. The idea is when one checkbox is clicked, the other option should be disabled. I'm have tried with radio control, but it doesn't work, because I have more than one question with same checkbox name.

Here is my current code

<form name=f1 method=post action="">
    <label>soal 1</label><br>
<input type=checkbox name=domi[] onclick="domi1(this.checked)" >A<br>
<input type=checkbox name=influ[] onclick="influ1(this.checked)">B<br><br>

    <label>soal 2</label><br>
<input type=checkbox name=domi[] onclick="influ2(this.checked)" >A<br>
<input type=checkbox name=influ[] onclick="stedi1(this.checked)">B<br><br>

<button type="submit">simpan</button>
</form>

Javascript code disabled the controls

 <SCRIPT LANGUAGE="JavaScript">
    function domi1(status)
    {
    status=!status; 
    document.f1.influ1.disabled = status;
    }

    function influ1(status)
    {
    status=!status; 
    document.f1.domi1.disabled = status;
    }
    </script>




Aucun commentaire:

Enregistrer un commentaire