开发者

Dropdownlist selected Value Sometimes returns text

开发者 https://www.devze.com 2022-12-18 10:22 出处:网络
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 displaye开发者_开发百

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 displaye开发者_开发百科d 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);
}

}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号