?
Solved

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

Posted on 2003-02-19
2
Medium Priority
?
1,178 Views
Last Modified: 2007-12-19
I have a Form containing a small set of radio buttons :

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

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
0
Comment
Question by:jah99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
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:

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

hope that helped.

Mungo
0
 

Author Comment

by:jah99
ID: 7982015
Lovely works a treat, thanks Mungo.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

762 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