[ start | index | login ]
start > Development > Javascript

Javascript

Created by mpecher. Last edited by mpecher, 2 years and 268 days ago. Viewed 1,493 times. #15
[diff] [history] [edit] [rdf]
labels
attachments
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
no comments | post comment

Menu:
Java & J2EE
Development
Books

Help:
Help FAQ
Formatting


< September 2010 >
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
2627282930


Logged in Users: (0)
… and 26 Guests.



Disclaimer: Views and opinions are that of the individual author, and not that of Marand Custom Solutions. This site is an open forum for technical content, and the company accepts no liability for any content or view expressed.