Form with checkbox unhides text field

B

Beagle

Folks,

I'm trying to write an html page that has a checkbox, such that
checking the box opens a text field. The submit button will post the
data. Any help much appreciated.

Thanks,
BEA
 
S

SAM

Beagle a écrit :
I'm trying to write an html page that has a checkbox, such that
checking the box opens a text field.


HTML :
======

<form blah blah >
<label for="chk_1">Hit the checkbox:
<input type=checkbox id="chk_1" onclick="reveal(this)">
<input class="hide" name="field_1">
</label>


CSS :
=====
label .hide { visibility: hidden }


JS :
====

function reveal ( what ) {
var target = what.parentNode;
while(target.tagName != 'LABEL') target=traget.parentNode;
target = target.getElementsByTagName('INPUT')[1];
target.className = what.checked? '' : 'hide';
}
 
S

SAM

SAM a écrit :
Beagle a écrit :


HTML :
======

Not a good idea this tag label :-(

HTML :
======

<form blah blah >
<P>Hit the checkbox:
<input type=checkbox onclick="reveal(this)">
<input class="hide" name="field_1">
</p>


CSS :
=====
p .hide { visibility: hidden }


JS :
====

function reveal ( what ) {
var target = what.parentNode;
while(target.tagName != 'P') target=traget.parentNode;
target = target.getElementsByTagName('INPUT')[1];
target.className = what.checked? '' : 'hide';
}
 
B

Beagle

Sweet!! Thanks, works, and WOW.


SAM a écrit :
Beagle a écrit :
HTML :
======

Not a good idea this tag label :-(

HTML :
======

<form blah blah >
<P>Hit the checkbox:
<input type=checkbox onclick="reveal(this)">
<input class="hide" name="field_1">
</p>

CSS :
=====
p .hide { visibility: hidden }

JS :
====

function reveal ( what ) {
var target = what.parentNode;
while(target.tagName != 'P') target=traget.parentNode;
target = target.getElementsByTagName('INPUT')[1];
target.className = what.checked? '' : 'hide';

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top