views:

96

answers:

1

I have a dropdown list on my form with Integer Values set and displaying text. When I run the following code to display the Value and then associated text, I find that the text is displayed in as value when it is not supposed to. Any work around to this please?

function OnddlChanged(dropdown) {

if( dropdown != null)
{
    var selindex = dropdown.selectedIndex;
    var selvalue = dropdown.options[selindex].value;
    var seltext = dropdown.options[selindex].text;
    document.getElementById('<%=Hidsel Key.ClientID %>').value = selvalue;
    alert(document.getElementById('<%=Hidsel Key.ClientID %>').value);
    alert(seltext);
}

}

A: 

Not 100% sure what you're trying to do here but the result of your code will indeed alert the text value of your dropdown list.

In your js function selvalue will hold the text associated with the selected item of your dropdownList. Its this text value that you are then assigning to the value of the dom element thats returned from <%=Hidsel Key.ClientID %>

So when you call alert - its the text value you will see.

Dav Evans
Yeah. For some reason it switches between text and integer as value. Not certain why.
Kobojunkie