Examples: JavaScript object model
- This JSHeader event handler declares a function that writes the product of the Width and Length fields to the SquareFeet field.
function getSquareFeet() { with (window.document.forms[0]) { SquareFeet.value = Width.value * Length.value } }This onFocus event handler for both the Length and Width fields calls the function:
getSquareFeet() - This Domino form onLoad event handler sets the window status display and then displays browser and platform information.
window.status = "Domino window opened" n = navigator alert (n.appName + " " + n.appVersion + " on " + n.platform) - This Domino hotspot onClick event handler loads a new URL by writing to the href property of the location object.
location.href = "http://localhost/Web+test.nsf/Main+View" - These onLoad event handlers are for two pages in a frameset. When the focus is on the first frame, the status bar displays "Page one." When the focus is on the second frame, the status bar displays "Page two."
window.status = "Page one" window.status = "Page two" - This onClick event handler for a page action displays the names of all the frames in a non-nested frameset.
for (n = 0; n < top.length; n++) { alert(top.frames[n].name) } - This onClick event handler for a page action displays the names of all the frames in a frameset that may contain one level of nesting.
for (n = 0; n < top.length; n++) { w = top.frames[n] if (w.length == 0) { alert (w.name) } else { for (nn = 0; nn < w.length; nn++) { ww = w.frames[nn] alert (w.name + ": " + ww.name) } } } - This onClick event handler for a page action displays the names of the applets on the page.
for (n = 0; n < window.document.applets.length; n++) { alert (window.document.applets[n].name) } - This code, placed in "Other" under the <HTML> tag of the HotSpot Properties box for a link hotspot, queries the user for a confirmation before going to the link.
onClick="return confirm('Go?')" - This code is for the onClick event handler of a picture named ThePicture. When the user clicks the picture, it changes to the image resource in "Web Test.nsf" named newdam.gif.
document.ThePicture.src = "/Web+Test.nsf/newdam.gif" - This onClick event handler for a button displays information about all the elements of the elements array in the current JavaScript form.
e = window.document.forms[0].elements for (n = 0; n < e.length; n++) { if (e[n].name == "") ee = "NO NAME" else ee = e[n].name t = e[n].type if (e[n].value == "") v = "NO VALUE" else v = e[n].value alert (ee + "\n" + t + "\n" + v) } - This onBlur event handler for FieldTwo forces FieldTwo to be blank if FieldOne contains the value "NONE."
one = window.document.forms[0].FieldOne.value two = window.document.forms[0].FieldTwo.value if (one == "NONE" && two != "") { window.document.forms[0].FieldTwo.value = "" alert ("FieldTwo must be blank if FieldOne is NONE") } - This onClick event handler for a button displays the selected values of a "Dialog list" field.
with (window.document.forms[0].MyList) { for (n=0; n<length; n++) { if (options[n].selected) { alert (options[n].text) } } } - This onClick event handler for a button displays all the hidden fields in the document. This only works in browsers and only if
Generate HTML for all fieldsis selected in the Domino Forms Properties box.with (window.document.forms[0]) { for (n=0; n<elements.length; n++) { if (elements[n].type == "hidden") { alert (elements[n].name + "\n" + elements[n].value) } } }