soundboy
08-05-2004, 10:23 PM
Hi... I posted this in the CSS forum, but now it's more of a JS problem, so I'll transcribe it here.
I have a drop down list, made with <select> and <option>. Now, there's an option which reads "other", and what I want is for users to click on that option and have an additional text input box appear. I'm doing that by changing the "display" CSS property.
Now, the following code works:
function showExtra (divName) {
document.getElementById(divName).style.display="inline";
}
So I'll have an option in a drop-down menu with an "OnClick=showExtra(div1)" and have that div with an initial "style=display:none".
But now I want to have the div disappear if the option is unselected, so I add this, but it stops working:
function showExtra (divName, selectName) {
if (document.formName.selectName.value == 'other') {
document.getElementById (divName).style.display="inline";
} else {
document.getElementById(divName).style.display="none";
}
}
Where formName is the name of the form and selectName is the name of my drop-down menu, which contains the option 'other', and is the one I want to trigger the visibility of the 'div1' element.
I figure there's something wrong with my syntax, but can't quite put my finger on it.
I have a drop down list, made with <select> and <option>. Now, there's an option which reads "other", and what I want is for users to click on that option and have an additional text input box appear. I'm doing that by changing the "display" CSS property.
Now, the following code works:
function showExtra (divName) {
document.getElementById(divName).style.display="inline";
}
So I'll have an option in a drop-down menu with an "OnClick=showExtra(div1)" and have that div with an initial "style=display:none".
But now I want to have the div disappear if the option is unselected, so I add this, but it stops working:
function showExtra (divName, selectName) {
if (document.formName.selectName.value == 'other') {
document.getElementById (divName).style.display="inline";
} else {
document.getElementById(divName).style.display="none";
}
}
Where formName is the name of the form and selectName is the name of my drop-down menu, which contains the option 'other', and is the one I want to trigger the visibility of the 'div1' element.
I figure there's something wrong with my syntax, but can't quite put my finger on it.