Forum Moderators: open

Message Too Old, No Replies

testing checkbox value to show/hide text field.

         

nelsonm

9:55 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



Hi all,

I have searched the forum but could not find a post on how to test the value of an html input checkbox (test if its checked) in order to show/hide a related text field. I hope someone can help.

Here's my half baked attempt...


<script type="text/javascript">

function showhide(textfield, checkbox) {
if (document.getElementById(checkbox).value == 'yes') {
document.getElementById(textfield).style.display = 'block';
}else{
document.getElementById(textfield).style.display = 'none';
}
}

</script>

<body>
<div id="part01">
<input name="ckbox" type="checkbox" id="ckbox" value="yes" onclick="showhide('txfield', 'ckbox')" />
<input name="txfield" type="file" id="txfield" size="33" style="display:none;" />
</div>
</body>

Will this work?

DrDoc

12:59 am on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should probably test against the
checked
property instead ...

[edited by: DrDoc at 1:01 am (utc) on Aug. 16, 2008]

nelsonm

2:24 am on Aug 16, 2008 (gmt 0)

10+ Year Member



Ok... How do i do that?