David G
David G

Reputation: 96790

How do select a radio button with JavaScript?

I've tried select(); check(); and even .selected = true; but I still haven't gotten around to selecting that radio button. Is there any way I can accomplish this?

Upvotes: 2

Views: 332

Answers (3)

Teario
Teario

Reputation: 741

Maybe you could post your code and we could give you a more complete solution?

To check a radio button I'm pretty sure it's .checked = true;

Upvotes: 1

Some Guy
Some Guy

Reputation: 16190

<input type=radio id='r'>
<script>
document.getElementById('r').checked=true;
</script>

Use .checked

Upvotes: 4

Felix Kling
Felix Kling

Reputation: 816272

You have to use the checked property:

element.checked = true;

Reference: HTMLInputElement

Upvotes: 6

Related Questions