JMosca77 Posted September 5, 2006 Share Posted September 5, 2006 Hi Everyone,Can anyone tell me how to change the values of a Radio Button via JavaScript?I have a Yes/No radio button on a form. When the user selects YES, a hidden layer is made visible with 3 fields for the user to fill out. When the user clicks a CLOSE, I want to update the YES option with the values entered in the layer. I've tried changing the innerText, innerHTML, and value but nothing updates the radio button options on the web page. Any suggestion? Link to comment Share on other sites More sharing options...
aspnetguy Posted September 5, 2006 Share Posted September 5, 2006 your radio buttons should share the same name (indicates a radio group)then you can do thisdocument.formName.radioGroupName[1].checked = true;this will work if the no radio button is second and yes is first. Link to comment Share on other sites More sharing options...
JMosca77 Posted September 5, 2006 Author Share Posted September 5, 2006 Thx for the reply. The radio buttons do share the same name. I guess what I'm trying to change is the Label for each radio button option, not which radio button is selected. your radio buttons should share the same name (indicates a radio group)then you can do thisdocument.formName.radioGroupName[1].checked = true;this will work if the no radio button is second and yes is first. Link to comment Share on other sites More sharing options...
scott100 Posted September 5, 2006 Share Posted September 5, 2006 I guess what I'm trying to change is the Label for each radio button option, not which radio button is selected.That's right, when you give the button a label there is no way to tie the two together, you will have to "mark" it some way so that you can access it's innerHTML, i have used span tags with unique id's to give you an idea of how it could work.<head><script>function update(spanId,val){document.getElementById(spanId).innerHTML=val;}</script></head><body><form><input type="radio" name="sox" value="male" onclick="update('male','I am a Man')" /><span id="male">Male</span><br><input type="radio" name="sox" value="female" onclick="update('female','You chose Woman')" /><span id="female">Female: </span></form></body> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now