Solved Make textarea appear

Microsoft / Vista
June 27, 2009 at 00:37:57
Specs: Windows Vista, 2GB
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:

<html lang="en">
<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') {

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

<form action="#" name="form1">
<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>

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.

See More: Make textarea appear

Report •

July 24, 2009 at 21:47:25
Never mind, I figured it out.

Report •

July 25, 2009 at 02:30:05
✔ Best Answer
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.

Report •

July 25, 2009 at 21:02:30
maybe you can help me with my new question then:

oh and how would I place that in my script?

Report •

Related Solutions

Ask Question