mike_g Posted April 2, 2007 Share Posted April 2, 2007 I want to change the selected radio box in a form using javascript. I couldent seem to find any examples in the W3 tutorials and I havent been able to work it out for myself yet. Below is an example prog I made. The Change() function is my best guess at what would work, but it dosent. Can someone tell me how to do this right? Cheers. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>Page title</title><script>function Change(){ document.c_form.nclass.value = "A";}</script></head><body onload="Change()"> <form name="c_form"> A<input type="radio" name="nclass" value="A"> B<input type="radio" name="nclass" value="B"> C<input type="radio" name="nclass" value="C"> D<input type="radio" name="nclass" value="D"> </form></body></html> Link to comment Share on other sites More sharing options...
Patrick Posted April 2, 2007 Share Posted April 2, 2007 You weren't that far from a working solution <html><head><title>Page title</title><script>function Change(){ document.c_form.B.click();}</script></head><body onload="Change()"> <form name="c_form"> A<input type="radio" id="A" name="nclass" value="A"> B<input type="radio" id="B" name="nclass" value="B"> C<input type="radio" id="C" name="nclass" value="C"> D<input type="radio" id="D" name="nclass" value="D"> </form></body></html> I added an id attribute to your inputs and used the method click() to select B. 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