Example of using AJAX in the Notes client
Category domino
At Ben's request, here's a very basic example of how I've put AJAX to use within the Notes client: a ZIP code lookup.
Suppose you have a form that asks the author to populate address information. To save them a few keystrokes, you can make a quick AJAX call to obtain the city and state and populate them automatically. This is easier to implement than you might expect:
1. Paste the following into the JS Header section of the form (or include in a JavaScript library inserted into the JS Header as a resource):
2. Paste the following into the onBlur event of the ZIP code field:
3. Replace the element names above with the actual field names that you're using on the form.
At Ben's request, here's a very basic example of how I've put AJAX to use within the Notes client: a ZIP code lookup.
Suppose you have a form that asks the author to populate address information. To save them a few keystrokes, you can make a quick AJAX call to obtain the city and state and populate them automatically. This is easier to implement than you might expect:
1. Paste the following into the JS Header section of the form (or include in a JavaScript library inserted into the JS Header as a resource):
var gstrCity;
var gstrState;
var gvarXMLApp;
function getCityState(pstrZipCode) {
var strServiceURL;
var gvarXMLApp;
loadXMLDoc();
strServiceURL = "http://www.webservicex.net/uszip.asmx/GetInfoByZIP?USZip=" + pstrZipCode;
gvarXMLApp.open("GET", strServiceURL, true);
gstrCity = gvarXMLApp.getElementsByTagName("CITY");
gstrState = gvarXMLApp.getElementsByTagName("STATE");
}
function loadXMLDoc() {
gvarXMLApp = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
gvarXMLApp = new XMLHttpRequest();
} catch(e) {
gvarXMLApp = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
gvarXMLApp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
gvarXMLApp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
gvarXMLApp = false;
}
}
}
}
2. Paste the following into the onBlur event of the ZIP code field:
var strZIPCode = document.forms[0].elements("ZipCode").value;
if (strZIPCode != "") {
getCityState(strZIPCode);
document.forms[0].elements("City").value = gstrCity;
document.forms[0].elements("State").value = gstrState;
}
3. Replace the element names above with the actual field names that you're using on the form.








Comments
Posted by Ben Langhinrichs At 07:21:30 On 12/03/2005 | - Website - |
Posted by Tim Tripcony At 11:55:55 On 12/03/2005 | - Website - |
Posted by Tim Tripcony At 16:59:58 On 08/06/2006 | - Website - |
I have a question on notes client . Will notes supports getDocumentById method?
Thanks
Ram
Posted by ram At 20:24:09 On 08/04/2006 | - Website - |