clear text box based on radio button selection

Posted on 2005-03-08
Medium Priority
Last Modified: 2008-07-05
I have a set of radio buttons (yes and no) if user selects yes than text box 2 and 3 need to be cleared, if no is selected than text box 1 is cleared.
Question by:rayne101
LVL 63

Expert Comment

ID: 13489914
Here an example:

<input type=radio name="C1" onClick="f=this.form;f.T2.value=f.T3.value=''"> Yes
<input type=radio name="C1" onClick="this.form.T1.value=''"> No
<input type=text name="T1" value="T1">
<input type=text name="T2" value="T2">
<input type=text name="T3" value="T3">

LVL 32

Accepted Solution

ldbkutty earned 2000 total points
ID: 13489923
<script language="JavaScript" type="text/javascript">
function clearFlds() {
 if(f.r1[0].checked) {
 else if(f.r1[1].checked) {
<form name="myform" method="post" action="" onSubmit="return validate()">
<input type="radio" name="r1" value="yes" onclick="clearFlds()">Yes
<input type="radio" name="r1" value="no" onclick="clearFlds()">No
<input type="text" name="t1" value="text_box_1"/>
<input type="text" name="t2" value="text_box_2"/>
<input type="text" name="t3" value="text_box_3"/>

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 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