Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Dropdown and list box selection show/hides DIV

Reply
Thread Tools

Dropdown and list box selection show/hides DIV

 
 
chris_huh
Guest
Posts: n/a
 
      08-02-2006
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?

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      08-03-2006

chris_huh wrote:
> 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.


--
Rob

 
Reply With Quote
 
 
 
 
darwinist@gmail.com
Guest
Posts: n/a
 
      08-03-2006
chris_huh wrote:
> 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(N ewText);

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

 
Reply With Quote
 
darwinist@gmail.com
Guest
Posts: n/a
 
      08-03-2006
chris_huh wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
Dropdown List - Check if value exists in list prior to selection =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= ASP .Net 5 03-20-2007 11:05 PM
remove a selection from a dropdown list box. =?Utf-8?B?UGF1bA==?= ASP .Net 7 04-28-2005 04:15 PM
list box in a div selection on postback problem Tim Donovan ASP .Net Web Controls 1 02-18-2005 08:46 PM
Facing problem in displaying dropdown menu(list box with single selection)in JSP Vitthal Bhat via JavaKB.com Java 1 01-25-2005 09:51 PM



Advertisments