Computing.Net > Forums > Web Development > Make textarea appear

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Make textarea appear

Reply to Message Icon

Name: You know who we are.
Date: June 27, 2009 at 00:37:57 Pacific
OS: Windows Vista
CPU/Ram: 2GB
Product: Microsoft / Vista
Subcategory: HTML
Comment:

Hello y'all, I am trying to put a feature one of my webpages so that when you click a button, a textarea will appear. The code I am currently using to do that job is this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Add input</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function addInput(f) {
var aInputs=f.getElementsByTagName('input');
for(var i=0; i<aInputs.length; i++) {
if(aInputs[i].className=='hide') {
aInputs[i].className='';
break;
}
}
}
</script>

<style type="text/css">
input {display:block;}
.hide {display:none;}
</style>

</head>
<body>
<form action="#" name="form1">
<div>
<input type="text" name="txt1">
<input class="hide" type="text" name="txt2">
<input class="hide" type="text" name="txt3">
<input class="hide" type="text" name="txt4">
<input class="hide" type="text" name="txt5">
<button type="button" onclick="addInput(this.form);">Add</button>
</div>
</form>
</body>
</html>


I found this code on the internet, it works fine except the text area is an input box and not a textarea. I have tried changing the "input" to "textarea" and setting the size, but the page wouldn't load. Is there any
explanation why this would happen? Does anyone know how to fix this problem or have a different script that I can use? Please let me know.



Sponsored Link
Ads by Google

Response Number 1
Name: You know who we are.
Date: July 24, 2009 at 21:47:25 Pacific
Reply:

Never mind, I figured it out.


0

Response Number 2
Name: Fist (by fmwap)
Date: July 25, 2009 at 02:30:05 Pacific
Reply:

You know if you use jQuery you can literly do all of that in this much javascript:

$('button').click(function() { $('input').toggle(); });

?

It's so much easier...I love not having to use PITA getElementById and TagNames and onClick blah blah's any more


Just my two cents.


0

Response Number 3
Name: You know who we are.
Date: July 25, 2009 at 21:02:30 Pacific
Reply:

maybe you can help me with my new question then:

http://www.computing.net/answers/wi...

oh and how would I place that in my script?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Make textarea appear

Make textarea accept pasted HTML www.computing.net/answers/webdevel/make-textarea-accept-pasted-html/3645.html

Image display question www.computing.net/answers/webdevel/image-display-question/148.html

Java hidden & visible form elements www.computing.net/answers/webdevel/java-hidden-amp-visible-form-elements/2778.html