Hi Everyone,
I want a text box which is only visible if the preceding drop down box has a certain option selected.
Does anyone know how to do this or where I might be able to find the appropriate code?
Thanks,
Dan
| SitePoint Sponsor |

Hi Everyone,
I want a text box which is only visible if the preceding drop down box has a certain option selected.
Does anyone know how to do this or where I might be able to find the appropriate code?
Thanks,
Dan

ok this is what I've done so far, but it still doesn't work.
I've placed a <div> with the id "audit" around the text box and set the style to visibility:hidden. Then on the drop down menu called "type", I've placed an onchange which performs the function called visible_no.
The code for visble_no is:
<i>function visible_no(){
if (document.type.value = "audit issue") {
div.audit.style = "visibility:visible";
}
else{
div.audit.style = "visibility:hidden";
}</i>
If anyone can help, I'd greatly appreciate it.
Thanks.

forget the <i>'s I thought it would display my code in italics
I think you've got an onchange handler in your select tag haven't you?Code:function visible_no(what){ if (what.value = "audit issue") { div.audit.style.visibility = "visible"; } else{ div.audit.style.visibility = "hidden"; }
Go here to read about how to post code 'userfriendy'Code:<form name="form1" action="" enctype=""> <select name="type" onchange="javascript:visible_no(this);"> <!--...//--> </select> </form>![]()
I beg your pardon for my bad English

Yep, I had an onchange in the select tag.
It's now telling me that "div is not defined" (referring toin the function.)PHP Code:div.audit.style.visibility = "visible";
This is how I've got the <div> in the body code.
PHP Code:<div id="audit" style="visibility:hidden">Audit No. : <input type="text" name="textfield"></div>

By the way, that's Netscape giving me that error. IE works fine.
I don't think it's necessary for it to work in Netscape because the only people that will need to fill in that visible/invisible field are people who work within the company and IE is the only browser in use.
So thanks for your help, Toxical.
Oh yes, havn't thought 'bout that div so far
try
I think, one of these possibilities should work in netscape as well.PHP Code:document.audit.style.visibility = "visible";
//or
document.all.audit.style.visibility = "visible";
//or
document.getElementById("audit").style.visibility = "visible";
I beg your pardon for my bad English

Toxical,Originally posted by Toxical
I think, one of these possibilities should work in netscape as well.PHP Code:document.getElementById("audit").style.visibility = "visible";
This was the one that worked. Thanks again for your help.
Dan
Bookmarks