473,795 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11210
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 setdivvisibilit y(show) {
if (show)
showvar="visibl e";
else
showvar="hidden ";
document.getEle mentById('div1' ).style.visibil ity=showvar;
}

Show Div <input type="checkbox" onclick="setdiv visibility(this .checked)"
checked>
<p>
Show Div<input type="radio" name=radiovisib ility"
onclick="setdiv visibility(true )" checked>
Hide Div<input type="radio" name=radiovisib ility"
onclick="setdiv visibility(fals e)" >

<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***@access4l ess.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 setdivvisibilit y(show) {
if (show)
showvar="visibl e";
else
showvar="hidden ";
The variable, showvar, is now global. Use the var keyword to keep it local.
document.getEle mentById('div1' ).style.visibil ity=showvar;
}


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.getEle mentById() is meaningful
if( !document.getEl ementById ) {
if( document.all ) {
document.getEle mentById = function( id ) {
return document.all[ id ];
};
} else {
document.getEle mentById = function() {
return null;
};
}
}

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

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

/*
* Alternatively:
* obj.style.displ ay = 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.******@blueyo nder.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
10667
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 this to seamlessly present the submitted data in an attractive format while hiding his submitted data in the hidden field...but I am not sure if there are restrictions of eg 255 characters for a hidden field? Many thanks Jason
4
25601
by: Max | last post by:
How can I disable scrollbars in a textarea. They seem to be enabled by default. thanks Max
6
1910
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 which has nothing but a couple of other asp files, like <frameset COLS="0,0,52%, *"> <frame NAME="hidden" SRC="MyHidden.asp"> <frame NAME="content" SRC="MyContent.asp"> </frameset>
5
5723
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 an item to the shopping cart. In this way, the entire page doesn't need to submit, only a hidden IFRAME, and I can make sure that if the user decides to hit the back button at any time, or even browse away from the page and come back, their...
2
5584
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: situation: (STAGE 1 = typing <a href="link">message</a>) <form method="post">
16
2856
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 criteria and at the bottom of this list i have a button that inserts all these records to a´nother table in the database. So long everything's ok. BUT, at the top of this list I have a textarea that the user can write down some text to be put...
1
2025
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
7084
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 action="http://cm1web1/WebSurveyComponents/script/ processform.asp" method="post">
0
1285
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> <script language="javascript" type="text/javascript" src="javas/ckeditor.js"></script> <script src="sample.js" type="text/javascript"></script>
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.