使用javascript在dojo filteringselect中获取所选值 [英] Getting selected value in dojo filteringselect using javascript

查看:88
本文介绍了使用javascript在dojo filteringselect中获取所选值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用dojo filteringselect控件并绑定来自DB的值。我想在javascript中进行验证,并希望获取所选值。当我这样做时,我得到一个错误

''options'为null或不是对象'。请帮助克服这个问题,下面是javascript和aspx代码。



JavaScript:



var sel = document.getElementById(testdropdown);

var str1Try = sel.options [sel.selectedIndex] .value;





< select dojotype =dijit.form.FilteringSelectautocomplete =trueid =testdropdownname =testdropdownstyle =width:200px; runat =server>



提前致谢,

Janes

Hi,

I am using dojo filteringselect control and bind the values from DB. I want to do a validation in javascript and want to take the selected value. When I am doing this I got an error
''options' is null or not an object'. Kindly help to overcome this issue and below is the javascript and aspx code.

JavaScript:

var sel = document.getElementById("testdropdown");
var str1Try = sel.options[sel.selectedIndex].value;


<select dojotype="dijit.form.FilteringSelect" autocomplete="true" id="testdropdown" name="testdropdown" style="width: 200px;" runat="server">

Thanks in advance,
Janes

推荐答案

说这是你的选择清单:



Say this is your select list :

<select id="testdropdown">
<option value="1">Option1</option>
<option value="2" selected="selected">Option2</option>
<option value="3">Option3</option>
</select>




var sel = document.getElementById("testdropdown");
var optionValue = sel.options[sel.selectedIndex].value;
var optionText = sel.options[sel.selectedIndex].text;





o / p

optionValue = 2

optionText = Option2



请检查您的选择是否list有值。



o/p
optionValue = 2
optionText = Option2

So check whether your select list have the value.


我不知道你使用的是哪个资源管理器,但是在IE中,如果你为id和name属性提供相同的名称,那么它通过该类型错误。
I don't know which explorer you using but, in IE if you provide the same name for "id" and "name" attribute , then it through that type of error.


//For most of the dijit.form widgets, the value can be fetched by widget.get('value')
var value = dijit.byId('testdropdown').get('value');


这篇关于使用javascript在dojo filteringselect中获取所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆