?
Solved

clear text box based on radio button selection

Posted on 2005-03-08
2
Medium Priority
?
869 Views
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.
0
Comment
Question by:rayne101
[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
 
LVL 63

Expert Comment

by:Zvonko
ID: 13489914
Here an example:

<html>
<body>
<form>
<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">
</form>
</body>




0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 2000 total points
ID: 13489923
<html>
<head>
<script language="JavaScript" type="text/javascript">
function clearFlds() {
 f=document.myform;
 if(f.r1[0].checked) {
  f.t2.value='';
  f.t3.value='';
  f.t1.value=f.t1.defaultValue;
 }
 else if(f.r1[1].checked) {
  f.t1.value='';
  f.t2.value=f.t2.defaultValue;
  f.t3.value=f.t3.defaultValue;      
 }
}
</script>
</head>
<body>
<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"/>
</form>
</body>
</html>
0

Featured Post

Technology Partners: 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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

770 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