marifrahman
marifrahman

Reputation: 690

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 ?

Upvotes: 2

Views: 992

Answers (3)

Janak
Janak

Reputation: 5052

You can use a flag and return false whenever the pre codition is not met....

 var IsIncidenntTypeSelected = 0;    // flag - sets to 1 when pre condition is met 
 $("input[type='radio']").click(function()
 {
       if(IsIncidenntTypeSelected  == 0)
            return false;
 }

Upvotes: 0

PSL
PSL

Reputation: 123739

Try this

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

Demo

Upvotes: 1

Amit Garg
Amit Garg

Reputation: 3907

You should user return propertyDamageType_click() . See the http://jsbin.com/uvopek/1/edit

Upvotes: 1

Related Questions