Thread: Onclick

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    21
    Rep Power
    0

    Onclick


    Hi,

    I have three radio buttons: New, Approved and Not Approved and one check box is Prize. When i click on Approved, i want Prize check box is enable, others, Prize check box needs to disable. The code i have below seems working fine but it wired

    1. When i click click on Approved, the check box is clickable but it looks grey out but if lick anywhere outside then the check box look clear

    2. When i click on either New or Not approved, the check box looks clear but not allow you to check on, but if I click any where outside then check box grey out as disable.
    Can you please help?


    //enable prize check box when approve is checked
    function setCompleted(){
    var completed = document.getElementById("approved2");
    if(completed.checked)
    document.getElementById("prize").disabled = false;
    else
    document.getElementById("prize").disabled = true;
    }


    //disable prize check box when new is checked
    function setCompleted1(){
    var completed = document.getElementById("approved1");
    if(completed.checked)
    document.getElementById("prize").disabled = true;
    else
    document.getElementById("prize").disabled = false;
    }

    //disable prize check box when not approved is checked
    function setCompleted2(){
    var completed = document.getElementById("approved3");
    if(completed.checked)
    document.getElementById("prize").disabled = true;
    else
    document.getElementById("prize").disabled = false;
    }



    <input type="radio" id="approved1" name="approved" value="0" onchange="setCompleted1();" >New
    <input type="radio" id="approved2" name="approved" value="1" onchange="setCompleted();" >Approved
    <input type="radio" id="approved3" name="approved" value="2" onchange="setCompleted2();" >Not Approved <br />

    <input type="checkbox" name="prize" id="prize" value="1">Prize?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    26
    Rep Power
    0
    In some browsers onchange
    does not fire until the element
    loses focus, as suggested in
    your title use onclick instead.

IMN logo majestic logo threadwatch logo seochat tools logo