Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Form Question

Form Question
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2004
Status: Offline
Reply With Quote
Mar 26, 2004, 08:44 PM
 
Hi Everyone. I hope that someone can help me with a problem that I am having and I thank everyone who reads this.

Ok, here is my problem:

Just alittle background- I am using DreamweaverMX, and I am creating a table inside a form.

I am trying to create a feedback form. In one of the fields, I am using a checkbox yes/no, which is on the left side of the table. On the right side, I am asking the user if he/she would like email updates. What I want to do is this: If the user clicks the checkbox, a text area will appear where the user can input there email address. If they don't click the checkbox, the text area will not appear.

I hope that I have explained it well enough to understand.

Anyone have any ideas?

I have tried entering in Javascript, but can't seem to get it correct. I have also tried to do a onClick behavior, but can't get that right.

Any suggestions/code samples would be greatly appreciated.

Thanks in Advance for your help!

Don
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 27, 2004, 06:16 AM
 
Try this:

Code:
<html> <head> <script> function showHide(what) { var t = document.getElementById("whatever"); (what.checked == true) ? t.style.visibility = "visible" : t.style.visibility = "hidden"; } </script> </head> <body> <input type="checkbox" onclick="showHide(this)"> <input type="text" id="whatever" style="visibility: hidden"> </body> </html>
I tried it in IE and firebird and it worked... I'm a bit perplexed as to why firebird (I'm at my parents and it's the only Moz browser they have, as well as IE) wouldn't accept what.getAttribute("checked") and I had to use what.checked... Oh well...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Fresh-Faced Recruit
Join Date: Mar 2004
Status: Offline
Reply With Quote
Mar 27, 2004, 08:30 PM
 
Thank You Very Much for the code and the quick response.

That did the trick and it works like a champ!

I hate to ask you something again, but, I am also trying to get it to work for series of 4 buttons ( button 1, button 2, button 3, button other). If the user clicks other, I am trying to get the same thing - a text box appears for the user to put in other information. I almost have it working, using your code of course. If I click the other button, the box appears. But if I click a either button 1-2 or 3, the box doesn't go away.

Thanks again for your help and any addtional help is greatly appreciated!

Thanks,

Don
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 29, 2004, 03:54 AM
 
Hi again - sorry for the delayed reply.

I'm not too sure what it is you want to do. If you click on one button the text area appears, but if you click on either of three others, then it goes away? What's the clause for clicking on the button which shows the text box again? does it disappear like it would when clicking the checkbox twice?

Sorry i can't be of more help at the moment - I'm just not too clear what it is you want...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Fresh-Faced Recruit
Join Date: Mar 2004
Status: Offline
Reply With Quote
Mar 29, 2004, 05:40 AM
 
Thanks for the assistance again. Basically I want a user to choose a dollar amount that they would feel comfortable to donate to a party ( this is for a neihborhood website). So they can either choose $20, $30, $40, $50 or other. So if they choose other, I wanted to give them a text area to write in an amount that they wanted to contribute. If they choose $20, $30, $40 or $50, the box would never show up. It would only show up if they choose other. I have it working, kinda of. The box is hidden if they choose $20, $30, $40 or $50 and if they choose other, it appears. But if they click other first, then decide to choose $20, $30, $40, $50, the box doesn't dissapear.

This is not a show stopper by any means. It works fine and I can live with the box not going away. The main issue was the checkbox one that you have helped me with. I am glad that you followed up on this posting so you could know that I am very thankful for that and for the help you are giving me now!

Thanks again and I hope I cleared up any confustion with my request.

Don
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 29, 2004, 06:01 AM
 
oh right, I see.

basically, just do very similar as before.
On the rest of the checkboxes, have an onclick attribute of
Code:
document.getElementById("whatever").style.visibility = "hidden"
that'll work, but isn't very elegant.
I'd propose this instead:
Code:
<html> <head> <script> function showHide(what) { var t = document.getElementById("whatever"); (what.checked == true) ? t.style.visibility = "visible" : t.style.visibility = "hidden"; } function hide() { var t = document.getElementById("whatever"); if (t.style.visibility == "visible") t.style.visibility = "hidden"; } </script> </head> <body> <input type="checkbox" name="money_20" onclick="hide()"> <input type="checkbox" name="money_30" onclick="hide()"> <input type="checkbox" name="money_40" onclick="hide()"> <input type="checkbox" name="money_50" onclick="hide()"> <input type="checkbox" name="money_other" onclick="showHide(this)"> <input type="text" id="whatever" style="visibility: hidden"> </body> </html>
Which is still not too good, but does work
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Fresh-Faced Recruit
Join Date: Mar 2004
Status: Offline
Reply With Quote
Mar 29, 2004, 09:17 AM
 
You have impressed the heck out of me!

Works like a champ!

I can not thank you enough. I took a basic Javascript class at the local community college, but this was beyond what I had learned there. Is there any books or training materials that you would recommend to learn more?

I appreciate all of your help!

Thanks Again!

Don
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 29, 2004, 10:03 AM
 
Ehm, I'm trying to think what I would recommend... I've never read any books, just online references and looking at other peoples code.

I've been writing in javascript for just over 6 years, and nowadays I only look at the reference over at netscape and the mozilla documentation to see what bleeding-edge things I can get my teeth into. I'm sure someone else'll be able to recommend some good things, but I'm afraid I'm not the best person to help you in this department.
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:04 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2