cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving HTMLB DropdownListBox from JavaScript

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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?"

Former Member
0 Kudos

Hi Alexa,

<b>

var index = selected.getText();

</b> will get you the text of selected item.

Answers (4)

Answers (4)

Former Member
0 Kudos

That worked! Thanks for all your help, Prakash!

Former Member
0 Kudos

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

func = window(funcName);

Any ideas?

Thank you for your help!

Former Member
0 Kudos

Hi Alexa,

you have a bug in there as well. You should change the line to following.

<b>

func = window[funcName];

</b>

Former Member
0 Kudos

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?

Former Member
0 Kudos

sorry, you need to change the myFormID to htmlb_formid. So the line should look like following.

var funcName = htmlb_formid+ "_getHtmlbElementId";

Message was edited by: Prakash Singh

Former Member
0 Kudos

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.