Please turn on javascript in your browser to play chess.
Developers Forum

Developers Forum

  1. Standard member thire
    Xebite
    12 Jun '06 09:35
    I have three radiobuttons in a group. None of them is checked by default. If I check one of them, I can't uncheck it anymore, but I just need this. I thought of a little JavaScript that looks if the button was checked before when you click it and if it was checked, it toggles it (unchecks it).
    I never did anything with javascript, but I tried to to this, but I faild. Can anybody help me?
    Thomas
  2. Subscriber ouroborosonline
    Digital Alchemist
    12 Jun '06 14:49 / 3 edits
    Put this into the head of the page:

    [ script ]
    var state = new Array;

    function radio(button) {
    if (state[button.name] && state[button.name] == button.value) {
    button.checked = false;
    state[button.name] = '';
    }
    else {
    button.checked = true;
    state[button.name] = button.value;
    }

    return true;
    }

    [/ script ]

    In the body of your page you'd use:

    [ input type="radio" name="group" value="a" onclick="radio(this);" ] option a
    [ input type="radio" name="group" value="b" onclick="radio(this);" ] option b
    [ input type="radio" name="group" value="c" onclick="radio(this);" ] option c


    Where the square brackets are replaced by angle brackets in the HTML tags.
  3. Standard member thire
    Xebite
    12 Jun '06 15:15
    WOW, simply perfect.
    I try to contribute this to the project online php script for leagues, see the german forum http://www.liga-manager-online.de/phpBB2/viewtopic.php?t=6930
    THANKS A LOT!
    Thomas