Solved

Show a textbox when radio button is selected.

Posted on 2004-03-24
5
470 Views
Last Modified: 2012-08-13
I'm a total non-programmer, so please bear with me.  This is an easy score for you.

I can hack html to make flat pages, but interactivity eludes me so far.

Here's what I want to do:

I have a form, and within the form I have 2 radio buttons.

If radio button 1 is selected (as default) then a text box should not be visible.
if radio button 2 is selected, a text box should appear right next to the check box.

Here's the section of my ugly code so far:

 <tr>
   <td height="32" class="xl24" style="height: 100%; border-top-style: none; border-top-width: medium" width="100%">
      <font face="Verdana">How should we reach you?
            <input type="radio" name="ContactBy" value="Email" checked>Email&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="ContactBy" value="Phone" onclick="if (this.checked) {Trouble.hidephone.display='true'} else {Trouble.hidephone.display='false'}">Phone&nbsp;&nbsp;&nbsp;
     
     <script>
     <div name="hidephone" id="hidephone">
      #</font> <input type="text" name="Phone" size="20"><font face="Verdana" size="1"><font class="font5"></font></font>
            </div>
     </script>
 </td>
</tr>

0
Comment
Question by:nummagumma2
  • 2
  • 2
5 Comments
 
LVL 7

Assisted Solution

by:gam3r_3xtr3m3
gam3r_3xtr3m3 earned 50 total points
ID: 10672488
<tr>
   <td height="32" class="xl24" style="height: 100%; border-top-style: none; border-top-width: medium" width="100%">
      <font face="Verdana">How should we reach you?
            <input type="radio" name="ContactBy" value="Email" onClick="document.getElementById('hidephone').style.display='none';" checked>Email&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="ContactBy" value="Phone" onClick="document.getElementById('hidephone').style.display='block';">Phone <div name="hidephone" id="hidephone" style="display: none;">&#160;&#160;&#160;#<input type="text" name="Phone" size="20"></div>
 </td>
</tr>
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 10673079
Great!

This is functional, but the textbox appears on the next line instead of just to the right of the radiobox.

Can you tune that part of it?
0
 
LVL 25

Accepted Solution

by:
devic earned 50 total points
ID: 10673445
<table border=0 cellspacing=0 cellpadding=3>
<tr style=font-family:Verdana>
      <td height=32>How should we reach you?</td>
      <td><input type="radio" name="ContactBy" value="Email" onClick="document.getElementById('hidephone').style.display='none';" checked></td>
      <td>Email</td>
      <td><input type="radio" name="ContactBy" value="Phone" onClick="document.getElementById('hidephone').style.display='';"></td>
      <td>Phone</td>
      <td id="hidephone" style="display: none;">#<input type="text" name="Phone" size="20"></td>
</tr>
</table>
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 10674470
I split the points, but I think you'll both find the amount to be fair.

The second answer worked exactly as I wanted.

Thanks guys.
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 10675139
glad to help. =p

gam3r
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now