Solved make a hidden button + textbox

Microsoft / Vista
July 25, 2009 at 17:00:40
Specs: Windows Vista, 2GB
Hello I am making a webpage and I want a textbox and a submit button to appear when I different button is clicked here is the code I am using:


<html>
<head>
<title>test</title>

<script type="text/javascript">
function addInput(f,a) {
var aInputs=f.getElementsByTagName('textarea');
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>
<textarea id="box1" cols="75" rows="5" class="hide" type="text"
name="box1"></textarea>
<button type="button" id="box2" class="hide"
name="box2">Confirm</button>
<button type="button"
onclick="addInput(this.form);">Comment</button>
</div>
</form>

</body>
</html>


I don't know how to make the button appear, can anyone help please, or if I could make the comment button work to make the textbox appear and then make it be comment the second time it is pressed, is that possible? Or could I get the button to work to, maybe something like this:

var aInputs=f.getElementsByTagName('textarea' 'button');

I don't know, Please help, I have seen these kind of things work before on facebook and some other sites, but how?


See More: make a hidden button + textbox

Report •


#1
July 26, 2009 at 14:13:30
You would do better to post this in the Web Development forum.

Report •

#2
July 26, 2009 at 16:05:26
I know, but this site was being stupid and only giving me an
option of about 5 forums and they were all hardware thing
so I put it in this.

Report •

#3
July 28, 2009 at 17:56:41
✔ Best Answer
Hey, answering your previous question from here: http://www.computing.net/answers/we...

jQuery is just a single javascript file that you include in a <script> tag, you can grab the latest version from here:
http://code.google.com/p/jqueryjs/d...

In jquery you can target dom elements via CSS selectors, and that's really where the beauty of it lies - you can target elements using good ole CSS.

So, the page would look something like this:
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
//fires after body loads
$(function() {
//When the id=clickme_button is pressed
$('#clickme_button').click(function() {
//Toggle visibility on the .hideme items
$('.hideme').toggle();
});
});
</script>
<style type="text/css"><!--
.hideme { display: none; }
--></style>
</head>
<body>
<input type="button" id="clickme_button" value="Click me" />

<input class="hideme" type="button" value="Some value" />
<textarea class="hideme"></textarea>
<p class="hideme">All the elements with a CSS class of hideme get selected</p>
</body>
</html>

The base download can do a lot, check the documentation for examples here:
http://docs.jquery.com/Main_Page


Report •

Related Solutions

#4
July 29, 2009 at 03:27:01
Thank you so much, that may be one of the best answers I have gotten from this site, but one more thing, what if I want to or more of those kind of buttons on the same
page, I don't want the first button to control everything on the page, just some of them, is that possible?

Report •

#5
August 10, 2009 at 18:59:01
Never mind, I figured out how to do more than one, but I uploaded my files and for some reason it doesn't work. is there a way to do it without using jQuery and using just
plain javascript? go to this site http://glitch.vndv.com/ it is the code you posted up here, I put the files in the right directory but it just doesn't work.

Report •


Ask Question