Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Function to catch Enter key press

Function to Catch Enter Key press and accordingly perform the required task:

function catchEnter(){
        if(window.event.keyCode == 13){
                document.all.S.click();
        }
}

Validation date and number through regular expression

Validation of number through regular expression:

function validateNumber( f ) {
        var regex = new RegExp();
        //regex = /^\d+$/;
        regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/
        if ( regex.test( f.value ) ) {
                return;
        } else {
                alert("Please enter a number value");
                f.value = "";
                f.focus();
                return;
        }
}


Validation of date through regular expression:

function CheckDate(dateV)
{
        var dateStr = dateV.value;
        if(dateStr==""){
                return;
        }
        if(dateStr=="tbd" || dateStr=="TBD"){
                return;
        }
        isValidDate(dateV, dateStr);
}


function isValidDate(dateV, dateStr)
{
        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
        var matchArray = dateStr.match(datePat);  
        if (matchArray == null) {
                alert("Date is not in a valid format.")
                dateV.focus();
                return;
        }
        month = matchArray[1]; // parse date into variables
        day = matchArray[3];
        year = matchArray[4];
        if (month < 1 || month > 12) {  
                alert("Month must be between 1 and 12.");
                dateV.focus();
                return;
        }
        if (day < 1 || day > 31) {
                        alert("Day must be between 1 and 31.");
                        dateV.focus();
                return;
        }
        if ((month==4 || month==6 || month==9 || month==11) && day==31) {
                alert("Month "+month+" doesn't have 31 days!");
                dateV.focus();
                return;
        }
        if (month == 2) {
                var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
                if (day>29 || (day==29 && !isleap)) {
                        alert("February " + year + " doesn't have " + day + " days!");
                        dateV.focus();
                        return false;
                }
        }
        return;
}

Refresh a form keeping its field values


To refresh a form keeping its field values as is:

http://authorsloft.com/SupportRef.nsf/e6b464faa52c14d1852567d90082c48f/1c05fb75304ce7a685256b710005fb38!OpenDocument

Copied the content from the above link:
Domino form / document refresh using JavaScript:

Better Option (Domino6 + ):
if(ValidationFunc()==true) {
return _doClick('$Refresh', this, null);
}

A longer version to specify a frame and what field to base refresh on:
return _doClick('$Refresh', this, '_self', '#_RefreshKW_' + 'somefieldname' );

To refresh the document

To refresh the entire document in client : @Command([ViewRefreshFields)
And to refresh entire document in web : _doClick('$Refresh', this, '_self', '#_RefreshKW_')

To run an agent from lotus notes webpage

To run a Lotus-script agent from a lotus notes webpage:

1) Write @Command([ToolsRunMacro]; "(MyWebAgent)") in the button's programmer pane Client > Formula and it will work when you click the button. No need to do Pass-thru HTML for this button.

If for some reason you are still not able to achieve your result, you can use an indirect approach, i.e.

2) In your button where you have written the code for running the agent, in it's Properties > HTML tab, give a name  and id to it. It's better if we keep the value for Name and ID same.

Then create another Button or link and in that write in the programmer pane Web > Javascript, document.forms(0).<the button's ID value>.click()

i.e. document.forms(0).btnCheckDuplicate.click()

Thus, the first button will be triggered with the click() event and your agent will run.

Proper way to logout a website...

Proper way to logout is a website in lotus notes:

After you use the default logout code you must redirect the page to another page.
This way if a PC is being used by multiple users it will not open the same session.
Once you redirect to another page, it kills the session completely post logout.

Syntax:
top.location = self.location.href.substring(0,self.location.href.indexOf('.nsf') +4) + "/<framesetname>?logout&redirectTo=http://"+window.document.forms[0].Server_Name.value+"/"+window.document.forms[0].DBNameTX.value+"/";

This is a response that I posted in IBM developers forum.
http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/7ba21b9304eaa6d6852570e500215ebf?OpenDocument