Skip to Content
author's profile photo Former Member
Former Member

Retrieving HTMLB DropdownListBox from JavaScript

Hi!

Does anyone know the correct JavaScript syntax to retrieve the Key and Value of the selected item from an HTMLB DropdownListBox?

I am doing something like the following, but I am missing the correct syntax for a few items:

var funcName = myFormID + "_getHtmlbElementId";

func = window(funcName);

var selected = eval(func("dropdown_id"));

var inf1 = eval(func("input_filed1"));

var inf2 = eval(func("input_field2"));

if (selected) {

var key = selected.getValue();

inf2.setValue(key);

//I don't know how to get the corresponding text for the selected key

var text = selected.getTextForValue();

inf1.setValue(text);

}

Thank you!

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 20, 2005 at 01:38 PM

    Thanks Prakash!

    Now that I am getting past those errors, I can see the output. Back to retrieving the key and value of the dropdownListBox items...

    selected.getValue() gives me the key of the selected item.

    select.getIndex() gives me the position of the selected item (i.e. 1, 2, etc).

    Do you know how I can retrieve the actual <i>value</i> of the selected item?

    If the item is defined as:

    <hbj:listBoxItem id="item1" value="This is Item 1" />

    I can get "item1" from .getValue(), but how do I retrieve "This is Item 1?"

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2005 at 05:21 PM

    Hi Alexa,

    The following syntax will get you the index and the value.

    var index = selected.getIndex();
    var value = selected.getValue();

    make sure you are setting the value<b> jsObjectNeeded = true</b> for your dropdown list box.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2005 at 06:01 PM

    Great! That worked. Now I get a 'Member Not Found' error at:

    func = window(funcName);

    Any ideas?

    Thank you for your help!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2005 at 05:45 PM

    Thanks for the hints!

    I am getting a 'myFormID is undefined' JavaScript error when the function is run. How, exactly, do I call the formID in the funcName line?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 23, 2005 at 11:49 AM

    That worked! Thanks for all your help, Prakash! 😊

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.