Uncheck a radio button during "onLoad" script?

Not applicable

I have a series of radio buttons that I need make sure are NOT CHECKED when a form is initially displayed.

Would anyone be willing to share some code that I can use during an "onLoad" script to uncheck any radio buttons that are checked by default? Or maybe there is a setting that I'm overlooking that will prevent a default check ..

Any help very much appreciated ..

8 REPLIES 8

Ivan Martez
ServiceNow Employee
ServiceNow Employee

You can set the default value in the dictionary of that field to false and it should be unchecked. No need to run a script.


Thanks. You got me on track.
I couldn't seem to find references in the dictionary to my radio button variable names. But I did set the "default" value for the variable to (null) which got me what I was looking for.


john_roberts
Mega Guru

null will work, and actually any value that doesn't match one of the choices will work. In this case null is not really null it's just another string value.
Where this is important is when you try to make the variable mandatory. If you default to anything then the mandatory check thinks you have a value, and you really do. If you don't set a default you get the first option selected.
Here's a client script I'm using to really clear the value onLoad to reverse the default value. It's still not the cleanest option but until we come up with a better option, like a variable parameter, then it should do the trick.



var var_ctrl = g_form.getControl('variable_name');
var_ctrl.value = '';


That makes a lot of sense. THANKS for describing the behavior of the default value. Oddly enough, I was wrestling with an issue (this morning!) with a "mandatory" item not behaving as expected. My use of the default value "null" was, in fact, causing the problem.

THANKS.