?
Solved

Facebook + Javascript + Hide - Show field Toggle = Headache

Posted on 2010-09-04
9
Medium Priority
?
596 Views
Last Modified: 2012-06-27
Hello all,

i would like to show or hide a text field on a form in html in a facebook app when I click a checkbox.  I know the code to set whether a checkbox is true/false is as follows and I was hoping there would be something similarly simple to hide or show a textbox:

    document.getElementById('CheckAnswerA').setChecked(false);

Any help you can offer would be greatly appreciated. Many thanks, Colin.

0
Comment
Question by:Canders_12
[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
  • 3
  • 3
  • 3
9 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33603124
From here : http://developers.facebook.com/docs/fbjs#dom_objects

I see we may use setStyle :


document.getElementById("texboxID").setStyle("display", "none");

Open in new window

0
 
LVL 2

Expert Comment

by:filosof
ID: 33603285
You need something like in the attached code snippet.

Additional notes:
In some cases maybe it makes sense to disable/enable the textarea as well - to suppress any input from sending to server etc..
...
<div>
<input type="checkbox"
 onclick="document.getElementById('mytext').style.display=(this.checked)?'':'none'">
</div>
...
<div>
<textarea id="mytext" style="display: none;"></textarea>
</div>
...

Open in new window

0
 

Author Comment

by:Canders_12
ID: 33603921
excellent :)

is it easy just to do the reverse and show the textfield?

many thanks, Colin.
0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 82

Expert Comment

by:leakim971
ID: 33603937
to show use block instead none

0
 
LVL 2

Expert Comment

by:filosof
ID: 33606778
leakim971
No, using "block" is not correct for all cases - better to use empty string ("") !

why:
1. "" will also show the text field
2. sometimes you need another value instead of "block" - that is specified by CSS classes of element etc.. - "bock" will override this feature, "" - not

Canders_12
my example does both: hides and shows


....style.display = (this.checked) ? '' : 'none';
or
....style.display = (this.checked) ? 'none' : '';

Open in new window

0
 

Author Closing Comment

by:Canders_12
ID: 33607213
Beautiful :)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33607707
Thanks for the points!
0
 

Author Comment

by:Canders_12
ID: 33612979
filosof,

sorry, you definitely deserve points here :(

is it against rules to pop up the same question to ensure you also get some points? sorry, i was rushing and didnt read everyones post.  Sorry dude.
0
 
LVL 2

Expert Comment

by:filosof
ID: 33614719
I do not know how to adjust - just ask some moderator etc.  - no matter
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…
Suggested Courses
Course of the Month8 days, 4 hours left to enroll

765 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