...

View Full Version : How to display a hidden layer when checkbox selected?



aerodesigns
05-09-2007, 12:31 AM
Hi there,

Basically I'm creating a HTML form and when the checkbox is selected, I need a textbox to be displayed to capture some content. I presume the best way would be with Javascript and possibly hidden layers - if anybody could suggest the relevent code then that would be great!

Thanks.

glenngv
05-09-2007, 01:46 AM
function toggle(chk){
chk.form.txt.style.display=(chk.checked)?"inline":"none";
}

<form>
<input type="checkbox" onclick="toggle(this)" />
<input type="text" name="txt" style="display:none;" />
</form>

aerodesigns
05-09-2007, 07:31 AM
Thanks for the quick help on that - I also need to set the text corresponding to the new input text box to be hidden and then display as well, do you know how that would work?

Many thanks for your help.

glenngv
05-09-2007, 11:12 PM
function toggle(chk){
document.getElementById("divTxt").style.display=(chk.checked)?"inline":"none";
}

<form>
<input type="checkbox" onclick="toggle(this)" />
<div id="divTxt" style="display:none;">
<label for="txtId">Text:</label>
<input type="text" name="txt" id="txtId" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum