Search code examples
javascriptradio-buttonprototypejsdom-events

Radio button to Prevent to be checked after on click


I am trying to prevent a radio button not to be checked if a false is returned from the onclick. Following is the jsbin link for the code I am using. http://jsbin.com/oruliz/2/

Is there anything I am missing; BTW, I am trying to use JS with no framework.

However, if pure js has this issue is there a workaround for prototyoe.js ?


Solution

  • Try this

    function propertyDamageType_click(elem) {
        if(yourconditionfails){ // or if(yourconditionfails && !elem.checked)
           elem.checked = false;
           alert('Please select an incident type');
        }
    }
    

    Demo