Saturday, January 16, 2010

User friendly information messages

In some situations you might want to provide the end user with some information. A way to do that is using alerts. But that is not always as user friendly as you might want.

Tanguy wrote a javascript for more user friendly messages that was improved by Si. I thought I could improve it a little further by making it more flexible and share the code with you.

Place the next function on the OnLoad event of the CRM form.

Notification = function(sNotification) {
    var elementId = 'Notifications';
    var id = 'divMessage';
    var src = document.getElementById(elementId);

    if ((sNotification == null) || (sNotification == "")) { = 'none';
    else {
        var newcontent = document.createElement("span"); = id;

        newcontent.innerHTML = "<table><tr><td><img src='/_imgs/ico/16_info.gif' /></td><td valign='top'>" + sNotification + "</td></tr></table>"; = "";

        var previous = src.firstChild;
        if (previous == null || previous.attributes['id'].nodeValue != id) {
            if (src.childNodes.length == 0)
                src.insertBefore(newcontent, src.firstChild);
            src.replaceChild(newcontent, previous);

Now you can call this function from anywhere on the form. For example on the exchange of accountnumber:

if(crmForm.all.accountnumber.DataValue != null)
    Notification("Accountnumber = "  + crmForm.all.accountnumber.DataValue);

Which results in the next information message:


No comments:

Post a Comment