-1

I'd like to disable the checkbox when an election is checked. Thank you

<form id="tform" method="post">
    Sélectionnez le type de la machine :<br>
    <input  type="checkbox" id="1" name="g"<?php if ($_POST['g'] == "pc") {echo  'checked="checked"';} ?> value="pc" class="checkbox"> Pc
    <input  type="checkbox" id="2" name="g"<?php if ($_POST['g'] == "wiiu") {echo 'checked="checked"';} ?> value="wiiu" class="checkbox">Wii U
    <input  type="checkbox" id="3" name="g"<?php if ($_POST['g'] == "xbox-360") {echo 'checked="checked"';} ?> value="xbox-360" class="checkbox">Xbox-360
    <input  type="checkbox" id="4" name="g"<?php if ($_POST['g'] == "playstation-4-ps4") {echo 'checked="checked"';} ?> value="playstation-4-ps4" class="checkbox">Ps4
    <input  type="checkbox" id="5" name="g"<?php if ($_POST['g'] == "playstation-3-ps3") {echo 'checked="checked"';} ?> value="playstation-3-ps3" class="checkbox">Ps3<br>
    <input  type="checkbox" id="6" name="g"<?php if ($_POST['g'] == "xbox-one") {echo 'checked="checked"';} ?> value="xbox-one" class="checkbox">One
    <input  type="checkbox" id="7" name="g"<?php if ($_POST['g'] == "nintendo-3ds") {echo 'checked="checked"';} ?> value="nintendo-3ds" class="checkbox">3ds
    <input  type="checkbox" id="8" name="g"<?php if ($_POST['g'] == "playstation-vita") {echo 'checked="checked"';} ?> value="playstation-vita" class="checkbox">Vita
    <input  type="checkbox" id="9" name="g"<?php if ($_POST['g'] == "iphone-ipod") {echo 'checked="checked"';} ?> value="iphone-ipod" class="checkbox">Iphone
    <input  type="checkbox" id="10" name="g"<?php if ($_POST['g'] == "android") {echo 'checked="checked"';} ?> value="android" class="checkbox">Anfroïd
    </form>
Boom
  • 41
  • 6

3 Answers3

2

how to put checkbox in disabled?

Simple

HTML

<input  type="checkbox" id="test" name="checkBoxName" disabled>

JS

document.getElementById("checkBoxID").disabled = true;

JQUERY

$("#checkBoxID").prop('disabled', true);
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
2

If you just want one answer to be possible, use radio buttons.

<input type="radio" />
Refilon
  • 3,334
  • 1
  • 27
  • 51
1

I think you don't want to disable but uncheck the checkbox when another is clicked, am I right?

You can either do this with an onclick handler on each input: http://jsbin.com/dunohofusi/edit

Or (and this is much easier) you change the type from "checkbox" to "radio" and the browser will do everything for you.

If you want the checkbox-look you can use css to change this back: http://jsbin.com/yodoridadu/edit

Nico Wiedemann
  • 174
  • 2
  • 10