Dropdown and list box selection show/hides DIV

C

chris_huh

I have a combo box whose values change depending on the value selected
in the dropdown menu beforehand. Essentially the drop down has
categories and the combo box are the actual topics.

That all works fine but know i need to find a way to show some text,
probably in a DIV, that is different for each of the values in the
combo box.
I have found a script that almost does this but it cannot work with the
combo box being changable.

Any one know how to do this?
 
R

RobG

chris_huh said:
I have a combo box whose values change depending on the value selected
in the dropdown menu beforehand. Essentially the drop down has
categories and the combo box are the actual topics.

That all works fine but know i need to find a way to show some text,
probably in a DIV, that is different for each of the values in the
combo box.
I have found a script that almost does this but it cannot work with the
combo box being changable.

Any one know how to do this?

Example, and caveat, below:

<select onchange="changeText(this);">
<option>one
<option>two
<option>three
</select>
<div id="xx"></div>
<script type="text/javascript">
function changeText(el){
var txt = el.options[el.selectedIndex].text;
var div = document.getElementById('xx');
while (div.firstChild) div.removeChild(div.firstChild);
div.appendChild(document.createTextNode(txt));
}
</script>


Warning:
- Feature detection omitted.
- No error checking performed
- Using onchange with select elements may create usability issues.
 
D

darwinist

chris_huh said:
I have a combo box whose values change depending on the value selected
in the dropdown menu beforehand. Essentially the drop down has
categories and the combo box are the actual topics.

That all works fine but know i need to find a way to show some text,
probably in a DIV, that is different for each of the values in the
combo box.
I have found a script that almost does this but it cannot work with the
combo box being changable.

Any one know how to do this?

// Make a text node:
NewText = document.createTextNode(This_Is_My_Text_Variable+" or literal
text");
// Put it into div by id
document.getElementById(DivObjectID).appendChild(NewText);

hth

If you used my system it would be half the code:
// Put text in div
PutIn($text("some text goes in here"), $(DivObjectID));

http://darwinist.googlepages.com/htmldesktop.html
 
D

darwinist

chris_huh said:
I have a combo box whose values change depending on the value selected
in the dropdown menu beforehand. Essentially the drop down has
categories and the combo box are the actual topics.

That all works fine but know i need to find a way to show some text,
probably in a DIV, that is different for each of the values in the
combo box.
I have found a script that almost does this but it cannot work with the
combo box being changable.

Any one know how to do this?

Oh, if you want to get the list index as well:

// list is a reference to the select box:
var optionvalue = list[list.selectedIndex].value;

hth
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top