javascript 如何从选项集 crm 4 dynamics 2011 online 中获取选定的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16737209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get selected value from a option set crm 4 dynamics 2011 online
提问by zirbel
This is a question related to using javascript with crm 4 2011 online
这是一个与在 crm 4 2011 online 中使用 javascript 相关的问题
I created an optionset -status: open,closed and a onchange event handler that calls the function run with the context as parameter.
我创建了一个选项集 -status: open,closed 和一个 onchange 事件处理程序,它以上下文作为参数调用函数运行。
In js i tried the following and more:
在 js 中,我尝试了以下以及更多:
function run(selectedItems)
{
var s = selectedItems[0];
}
But i always get an undefined variable.
但我总是得到一个未定义的变量。
How can get the selected value from a optionset?
如何从选项集中获取选定的值?
Thanks
谢谢
EDIT:
编辑:
i tried
我试过
function run() {
alert("hello");
var texter = Xrm.Page.getAttribute("new_state_request").getSelectedOption().text;
alert(texter);
}
just now. Gettin this: Error in userdefined event of this field. field:new_state_request event:onchange error:undefined
现在。开始:此字段的用户定义事件出错。字段:new_state_request 事件:onchange 错误:未定义
回答by Guido Preite
these are the right methods with an optionset attribute, for more information visit this link:
这些是具有选项集属性的正确方法,有关更多信息,请访问此链接:
http://msdn.microsoft.com/en-us/library/gg334409.aspx
http://msdn.microsoft.com/en-us/library/gg334409.aspx
get the text of selected option
获取所选选项的文本
Xrm.Page.getAttribute("fieldname").getText();
get the numeric value of selected option
获取所选选项的数值
Xrm.Page.getAttribute("fieldname").getValue();
回答by Scorpion
try
尝试
To Get the selected text of a OptionSet field
获取 OptionSet 字段的选定文本
Xrm.Page.getAttribute("CRMFieldName").getSelectedOption().text;
To Get the selected value of a OptionSet field
获取 OptionSet 字段的选定值
Xrm.Page.getAttribute("CRMFieldName").getSelectedOption().value;