Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes HTML, CSS and JavaScript and the fly likes javascript for radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript for radio button" Watch "javascript for radio button" New topic

javascript for radio button

Mark Butcher
Ranch Hand

Joined: Jun 28, 2012
Posts: 46
Hi there,

Am working on javascript and struts 1.3.
Want to uncheck a radio button using javascript.
Have tried that and its not working for me.
Here is the jsp code :

and the javascript :

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61086

The struts markup doesn't help us to know if your selector is correct. What's relveant is the actual HTML that is generated and sent to the browser.

But even if the selector is correct, why are you setting the value to false? The value has nothing at all to do with whether the radio element is checked or not. What you want to do is to set the checked attribute on the radio button.

Using jQuery (recommended) that'd be:
where whatever is the selector for the element.

In raw JavaScript, you use: document.getElementById('whatever').checked = true;

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61086

Oh, I see that you want to uncheck. Same deal, just false.
I agree. Here's the link:
subject: javascript for radio button