Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle textbox visibility 2

Status
Not open for further replies.

Slippenos

MIS
Apr 22, 2005
333
US
<select id = "dropDown" name="dropDown">
<option value="Nothing"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="***">Other</option>
</select>

I want to write a function, that, when 'Other' is selected- a textbox shows up next to the drop down.

Any thoughts?

 
you could define a text box in the HTML and use CSS to set the visibility:
style="visibility:hidden"
then in your function you can reveal it:
document.formName.textBoxID.style.visibility=visible

--kate
 
Do NOT use document.all unless your target audience is 100% IE users. Instead, use this variation of SarahKate's solution:

document.getElementById(textBoxID).style.visibility='visible';

Lee
 
<script language = "javascript">

function toggleVisibility () {

document.getElementById(Type2).style.visibility='visible';

}

</script>

<form name = "form">

<select id = "dropDown" name="dropDown">
<option value="Nothing"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="toggleVisibility();">Other</option>
</select>

<input type = "textbox" name = "Type2" id = "Type2"
style = "visibility:hidden">

</form>

Are you saying it should look like this?
 
i was kind of thinking:

<script language = "javascript">

function toggleVisibility() {
if(document.getElementById(dropDown).value=="4") {
document.getElementById(Type2).style.visibility='visible';
}
}
</script>
<form name = "form">

<select id = "dropDown" name="dropDown" onChange="toggleVisibility()">
<option value="Nothing"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">Other</option>
</select>

<input type = "textbox" name = "Type2" id = "Type2"
style = "visibility:hidden">

</form>
 
I tried that, and it says:

Error: 'dropDown' is undefined.

 
ok...add quotes around the element id:

document.getElementById("dropDown").value
document.getElementById("Type2").style.visibility

that worked for me...its always something stupid like that...

--kate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top