Using AJAX as a replacement for ©DBLookups
We have started implementing AJAX in a number of applications here at my work. Most of what we have done has been using agents to bring back HTML to change a web page using the .innerHTML property. But today I was thinking that I could just as easily bring back the same information I can get in an @DBLookup. The approach I took is very specialized, but can be expanded to pull back any information you would ever want. The JavaScript is as follows:

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getContactPhone(username, objID) {
  var obj = document.getElementById(objID);
  xmlhttp.open("GET", "/names.nsf/GetOfficePhone?OpenAgent&username=" + username);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      obj.value = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}

So I have the onBlur event for the contact field set to getContactPhone(document.forms[0].contact.value,'contact_phone'); so that the contact's phone number is looked up in the Public Address Book whenever the user tabs out of the field. The agent I created, GetOfficePhone, returns the user's phone number I want with 2 print statements:
Print "Content-type: text/plain"
Print doc.OfficePhoneNumber(0)

This technique could definitely be expanded to do full blown @DbColumn and @DBLookup functions.

<< Previous Document / Next Document >>
  • 1) Works like a charm in IE - Christopher Byrne
    Created 6/29/2005 9:25:13 AM email | website

    After slapping myself over stupid ACL mistakes on my test, I got it to work like a charm in IE. No go in Firefox or Netscape though until I set the "ID" in the HTML properties tab of the phone field. Will blog on this later.

  • 2) Good stuff... - Matt White
    Created 6/30/2005 2:41:46 AM email | website

    Nice work. A complete implementation of a Javascript DBLookup and a DBColumn function can be found here { Link }

  • 3) Nice Work - Ashish Sidapara
    Created 6/30/2005 11:04:10 AM email | website

    Matt has posted a link to a tip i had posted on Search Domino.

    That eventually was selected as Tip of the Month and i won an iPod Mini.

    cheers !!

    Ashish

  • 4) Good Work - Viresto ICT
    Created 4/20/2008 12:43:05 PM email | website

    Good work. Easy and convenient.

  • 5) Can Schedule Orders (and Schedule BPAs) Be Set-Aside for Small Business? - Mary
    Created 5/11/2010 6:48:04 AM email | website

    Hi;

    Unfortunately, although I realize I could not read the topic defalrca to help me in this regard would be glad if the mail.

    mary lou

    marylou23@gmail.com

    { Link }

  • 6) For Thanks - Ankara Oto Kiralama
    Created 7/29/2010 6:12:34 AM email | website

    Yaz sezonun gelmesiyle beraber bilinir ki oto kiralama'da büyük bir yoğunluk soz konusu olmuştur. Ankara'da oto kiralama hizmeti veren bir firma olan alper oto kiralama ankarada en iyi oto kiralama hizmeti veren firmalaradan biri olarak müşterilerini bu sezonda'da yanlız birakmayarak gerekli tedbirleri almış ve araç filosunu genişletmiştir.

Post A Comment
Subject: (required)
Name: (required)
Email: (required)
Web Site:
Comment:(No HTML - Links will be converted if prefixed http://)

Remember Me?