SSJS - Server Side JavaScript
------------------------------------
Edit Box, Check Box, Radio Button, Radio Button Group:
getComponent("ControlID").value
Check Box group:
...
Setting SSJS Values
------------------------------------
Edit Box:
getComponent("ControlID").setValue("something");
______________________________________________
CSJS - Client Side JavaScript
Getting CSJS Values
------------------------------------
Edit Box, Combo Box, Radio Button:
XSP.getElementById("#{id:ControlID}").value
Check Box:
XSP.getElementById("#{id:ControlID}").checked //will return 'true' if checked, 'false' if not checked
Check Box Group:
var checkField=document.getElementsByName("#{id: ControlID }");
var result=[];
for(var i=0;i<checkField.length;i++){
if(checkField[i].checked){
result.push(checkField[i].value);
}
}
alert(result.join(','));
Radio Button Group:
var result=null;
for(var i=0; i<document.forms[0].elements.length; i++){
if(document.forms[0].elements[i].name=="#{id:ControlID}" ){
if(document.forms[0].elements[i].checked == true){
result=document.forms[0].elements[i].value;
break; //remove this if for check box groups and collect multiple values above instead
}}}
alert(result); //result is the currently selected value of the radio group
Setting CSJS Values
-----------------
Edit Box:
XSP.getElementById("#{id:ControlID}").value = "something";
Radio Button Group:
function setRadioValue(id, value)
{
var elements = document.getElementsByName (id);
for(i=0;i<elements.length;i++) {
if (elements[i].value == value) {
elements[i].checked = true;
}
}
}
setRadioValue("#{id:radioGroup}", "value");
dojo.query("[name$=#{id:optionName}]:checked").length>0
ReplyDeleteFor Checkbox Group client side js try:
ReplyDeletevar checkField=document.getElementsByName("#{id:ControlID}");
var result=[];
for(var i=0;i<checkField.length;i++){
if(checkField[i].checked){
result.push(checkField[i].value);
}
}
alert(result.join(',')); //Returns all checked values of the check box group
Thanks! Added this.
DeleteGreat, works just fine!!!
DeleteThanks...it works superb!!!
DeleteHi Celina Insurance Developers,
ReplyDeleteThank a lot . I was searching for this. really helped me..saved my time
I am using checkbox group in xpages and the checkbox group value is computed. I tried all the above methods to retrieve the checked values from checkbox but nothing worked. I used the folowing method : getComponent(“Checkboxlist”).getAttributes().values() and it returns empty array. Anyone has any better ideas ? Please help
ReplyDeleteThis may help: http://stackoverflow.com/questions/9871872/how-can-i-get-the-checkbox-groups-label-value
ReplyDeletegetComponent("ControlID").setValue("something");
ReplyDeletei am not getting the setValue while using the getComponent, i am getting teh getValueBinding.
How to loop to get values from field whose ID are as Field_1, Field_2...Field_15
ReplyDeleteNeed it urgently
Hello. I would try posting your question on StackOverflow using the XPages tag: https://stackoverflow.com/questions/tagged/xpages.
DeleteYou could also try posting your question on the XPages forum: http://www-10.lotus.com/ldd/xpagesforum.nsf.
For Setting value in List Box CSJS:
ReplyDeletevar listbox = document.getElementById("#{id:Facility}");
for (var i=0; i<listbox.options.length; i++){
if (listbox.options[i].value == "10" || listbox.options[i].value == "15") {
listbox.options[i].selected = true;
} else {
listbox.options[i].selected = false;
}
}