This section is for Javascript related items, that are often used
1. <A> (Link) to trigger Javascript functionality
<a href="javascript:void(0)" id="link_ref" onClick="javascript:theFunction();">Link Test</a>
2. Confirm before following a link
<a href="#" onClick="javascript: return(confirm('Do you want to proceed'));">Confirm prior to following link</a>
3. Adding inline Javascript to onLoad event of page
This is useful if within a page, javascript needs to be added to the onload event. (Say if inside a Portlet, which doesn't have its own onload etc):
function addToBodyOnload(oFunction) {
var existingOnload = window.onload;
window.onload = function () { existingOnload(); oFunction(); }
}
Usage:
addToBodyOnload(someFunction);
or
addToBodyOnload(function () { document.getElementById("mainTable").focus(); } );
4. Radio Buttons / Dynamic Typing Gotchyas
Grapping Radio button from the form. This will return:
- an array for > 1 radio button
- the radio button element for = 1 radio button
Need to ensure this is tested (see below)
var radioButtons = form["someRadioButtons"];if (typeof(radioButtons.length)=="undefined") {
//holds the value itself not an array
return radioButtons.value;
} else {
for (var i=0; i < radioButtons.length; i++) {
if (radioButtons[i].checked) {
return radioButtons[i].value;
}
}
}
Trimming trailing spaces
To trim spaces use the following regular expression on the String:
/s+$/g
eg.
document.Login.username.value = document.Login.username.value.replace(/s+$/g, '');
Sites:
http://www.mattkruse.com/javascript/
http://www.javascriptkit.com/script/script2/timestamp.shtml
Calendar Popup
Rich HTML editors
http://wiki.moxiecode.com