Wednesday, December 22, 2010

Issues with document.getElementById of computed fields in xpages

This is one of the most irritating issues that I encountered in XPages. Again XPages are not the ones to be blamed, it was me- did not understand how the elements got rendered on the browser.

The issue in short is that I was not able to retrieve or set value to a Computed Field on an XPage using client script

Say my field name on the XPage is "XPageEditBox"

now, document.getElementById("#{id:XPageEditBox}").value did not help me to get or set the values of the edit box.

This was because, I though that the edit box will be rendered as a html field and that was not the case. It was rendered as a span tag.

So the way to access the values is as follows,

var myValue=document.getElementById("#{id:XPageEditBox}").innerHTML to get and

document.getElementById("#{id:XPageEditBox}").innerHTML=myValue to set

Hope this helps :)


  1. The edit box is actually a dijit Widget. So you can use dijit.byID

  2. Not sure when you need to use dojo and when to use dijit, I guess dojo will work as well.

    var d = dojo.byId("#id:inputbox}");

  3. typo...

    var d = dojo.byId("#{id:inputbox}");

  4. Thanks so much... I was struggling with this for days

  5. If possible, share any other issues that you may have struggled with or are struggling with.

  6. Thanks so much I was struggling before I saw your answer

  7. Thanks so much!!! From Uruguay. South America (Luis Suarez - Barcelona).