473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Hidden textarea

Is there anyway in JavaScript to hide/show a textarea based on what radio
button is selected? I am totally new to JavaScript and have no idea about
any of it.
Thanks.
Jul 23 '05 #1
2 11194
Ritesh Shah wrote:
Is there anyway in JavaScript to hide/show a textarea based on what radio
button is selected? I am totally new to JavaScript and have no idea about
any of it.
Thanks.


How about: put it inside a div and set div visibility, this works in my
IE6, Netscape 7.1, Firefox 0.8:

function setdivvisibility(show) {
if (show)
showvar="visible";
else
showvar="hidden";
document.getElementById('div1').style.visibility=s howvar;
}

Show Div <input type="checkbox" onclick="setdivvisibility(this.checked)"
checked>
<p>
Show Div<input type="radio" name=radiovisibility"
onclick="setdivvisibility(true)" checked>
Hide Div<input type="radio" name=radiovisibility"
onclick="setdivvisibility(false)" >

<div id="div1" name="div1">
<textarea rows="1" cols="20">
Sample Text Sample Text Sample Text Sample Text Sample Text Sample
Text Sample Text Sample Text
</textarea>
</div>

Jul 23 '05 #2
On Sun, 25 Apr 2004 19:08:59 -0700, mscir
<ms***@access4less.com.net.org.uk> wrote:
Ritesh Shah wrote:
Is there anyway in JavaScript to hide/show a textarea based on what
radio button is selected? I am totally new to JavaScript and have no
idea about any of it.
How about: put it inside a div and set div visibility, this works in my
IE6, Netscape 7.1, Firefox 0.8:


Why use a DIV? You're adding structure where there is none. The TEXTAREA
can be hidden directly. Furthermore, using the visibility property isn't
always appropriate: hidden elements still take up space. Depending on the
structure and layout of the OP's document, use of the display property
might be better.
function setdivvisibility(show) {
if (show)
showvar="visible";
else
showvar="hidden";
The variable, showvar, is now global. Use the var keyword to keep it local.
document.getElementById('div1').style.visibility=s howvar;
}


It would be a good idea to code defensively. I notice that you regularly
use methods, object and return values without checking for support. This
produces code that might fail and produce needless errors. Even
applications in C++, with a known environment, should be written
defensively, and more so for browser scripting.

// Make sure that document.getElementById() is meaningful
if( !document.getElementById ) {
if( document.all ) {
document.getElementById = function( id ) {
return document.all[ id ];
};
} else {
document.getElementById = function() {
return null;
};
}
}

function setVisibility( id, show ) {
var obj = document.getElementById( id );

if( obj && obj.style ) {
// Use an empty string to return to the default value.
obj.style.visibility = show ? '' : hidden;

/*
* Alternatively:
* obj.style.display = show ? '' : 'none';
*/
}
}

The call should now be modified to pass the id attribute value of the
TEXTAREA to be hidden.

[snip]

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jason | last post by:
Can someone tell me if it is possible to store the contents of a TEXT AREA field in HIDDEN FIELD in another page after the initial form containing the textarea is submittted.... I need to do...
4
by: Max | last post by:
How can I disable scrollbars in a textarea. They seem to be enabled by default. thanks Max
6
by: GoCMS | last post by:
Hi, guys: I am trying debug other people(who has left company)'s ASP code, and had difficulty understanding the use of a hidden asp page. The application has an index page, like MyIndex.asp...
5
by: David | last post by:
Hey, I'm not quite sure where to post this, but I believe this is the most appropriate place. I have a page I am creating that does a submission within a hidden IFRAME every time someone adds...
2
by: Ja NE | last post by:
and new problem... buit this time I haven't found solution in some manual... problem: I would like to allow <a href="link"> tag, but I'm having problems in hidden field when checking message: ...
16
by: Jen | last post by:
Hi. I have this problem that I think should be easy but have been struggling with this for days. I have a list based on a recordset from a database. This list consists of records meeting a certain...
1
by: nagamalli26 | last post by:
hai iam new php. i am creating admin side. i wrote this, phpcode: <?php //include_once("config.php"); $con=mysql_connect("localhost","root",""); mysql_select_db("happysalary"); ?>
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
0
by: samvb | last post by:
Am new to CKEditor though I have used tinymce before. What I liked about cheditor is its drop down styles feature. But I can't seem to get it to work at all. here is my code: <head>...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.