Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


JavaScript - How Do I reset Radio Buttons which have a preset default

Posted on 2003-02-19
Medium Priority
Last Modified: 2007-12-19
I have a Form containing a small set of radio buttons :

<INPUT checked=checked type="radio" name="sort" value="A">Option1
<INPUT type="radio" name="sort" value="B">Option2

I tried putting a simple reset button on the form, but it always resets to the Option1 radio button ticked (the default).  I need 1 to be ticked when the page is opened, but also need a button which will reset the radios so that neither are ticked.

Any idea how I can do this in javascript
Question by:jah99

Accepted Solution

Mungo_Clump earned 200 total points
ID: 7981288
I had a play about and managed to achieve this.

I used an "onload" event to check the first radio button. This way the reset button returns the radio's to their native state (ie: unchecked).

My code:

<body onLoad="document.form1.sort[0].checked = 1">
<form name="form1" method="post" action="">
    <INPUT name="sort" type="radio" value="A">
    <INPUT type="radio" name="sort" value="B">
    <input name="Reset" type="reset" value="Reset">

hope that helped.


Author Comment

ID: 7982015
Lovely works a treat, thanks Mungo.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question