How to Get a Client-Side Field Using JavaScript

Mindwatering Incorporated

Author: Tripp W Black

Created: 08/19/2010 at 02:36 AM

 

Category:
Notes Developer Tips
XPages

Issue:
How do I do client-side JavaScript (CSJS) processing or validation like I used to before Xpages without a round trip to the server?

Solution:

For a Field:
var mystring = document.getElementById("#{id:myEditBoxID}").value;
or
var mystring = XSP.getElementById("#{id:myEditBoxID}").value;
or
var mfld = dojo.byId("#id:myEditBoxID1");
alert (myfld.value);
(Note: look at the view source. Your field name probably has a 1 after it in a custom control. For example, in the GUI your field might be firstName, but really be firstName1.)

For a Combobox:
var tmpformfld = XSP.getElementById("#{id:myComboFld}");
var tmpform = tmpformfld[tmpformfld.selectedIndex].value;
(I like two lines for readability.)

For a XPage Computed Field
var mystring = XSP.getElementById("#(id:mycomputedid}").innerHTML;

Yes, you can get computed text on an Xpage !

previous page