Wednesday, August 10, 2011

To Check Internet Explorer (IE) version


Little helper function to return details about IE 8 and its various compatibility settings either use as it is or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is very common so use with caution.


function IEVersion(){
var _n=navigator,_w=window,_d=document;
var version="NA";
var na=_n.userAgent;
var ieDocMode="NA";
var ie8BrowserMode="NA";
// Look for msie and make sure its not opera in disguise
if(/msie/i.test(na) && (!_w.opera)){
// also check for spoofers by checking known IE objects
if(_w.attachEvent && _w.ActiveXObject){
// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
version = (na.match( /.+ie\s([\d.]+)/i ) || [])[1];
// Its IE 8 pretending to be IE 7 or in compat mode
if(parseInt(version)==7){
// documentMode is only supported in IE 8 so we know if its here its really IE 8
if(_d.documentMode){
version = 8; //reset? change if you need to
// IE in Compat mode will mention Trident in the useragent
if(/trident\/\d/i.test(na)){
ie8BrowserMode = "Compat Mode";
// if it doesn't then its running in IE 7 mode
}else{
ie8BrowserMode = "IE 7 Mode";
}
}
}else if(parseInt(version)==8){
// IE 8 will always have documentMode available
if(_d.documentMode){ ie8BrowserMode = "IE 8 Mode";}
}
// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions
ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5
}
}

return {
"UserAgent" : na,
"Version" : version,
"BrowserMode" : ie8BrowserMode,
"DocMode": ieDocMode
}
}
var ieVersion = IEVersion();
var IsIE8 = ieVersion.Version != "NA" && ieVersion.Version >= 8;

if (!IsIE8) {
alert("Please upgrade to Internet Explorer 8 or better!" ) ;
}

Wednesday, July 13, 2011

Masking a HTML TextField as Numeric or Float

Add these functions to your JavaScript code under <script> tag.

function getKey(evt) { // works for IE, Netscape, Firefox, Opera, Chrome

var theEvent = evt || window.event;

var key = theEvent.keyCode || theEvent.which;

return key;

}

function MaskNumeric(evt) {

//8 Delete, 39 left cursor, 37 right cursor, 35 end, 36 home, 9 tab, 116 f5

//127 Backspace 48-57 0-9

var key = getKey(evt);

if( (key == 116 || key == 8 || key == 9 || key == 39 || key == 37 || key == 35 ||

key == 36 || key == 189 || key == 109 || key == 127 || key == 46) ||

(key >= 48 && key <= 57) ||

(key >= 96 && key <= 105) ) {

return true;

} else {

return false;

}

}

function MaskFloat(evt) {

//8 Delete, 39 left cursor, 37 right cursor, 35 end, 36 home, 9 tab, 116 f5

//127 Backspace 48-57 0-9

var key = getKey(evt);

if( (key == 116 || key == 8 || key == 9 || key == 39 || key == 37 || key == 35 ||

key == 36 || key == 189 || key == 109 || key == 127 || key == 46 || key == 110 || key == 190) ||

(key >= 48 && key <= 57) ||

(key >= 96 && key <= 105) ) {

return true;

} else {

return false;

}

}


Then use the following code in your HTML form.

For Numeric Masked Field:

<input type="text" onkeypress="return MaskNumeric(event);" />

For Float Masked Field.

<input type="text" onkeypress="return MaskNumeric(event);" />


Wednesday, February 16, 2011

Passing Variable No of Arguments to Oracle Stored Procedure

If you want to pass variable number of arguments in a Oracle stored procedure, you can use array Type as stored procedure's parameter to accomplish this. Like in Java you can pass varargs as an array.

1- Create an Oracle nested table type in the database

CREATE OR REPLACE TYPE nt_type IS TABLE OF VARCHAR2(30);

2- Create a procedure in the database

CREATE OR REPLACE PROCEDURE nt_proc (nt nt_type) IS

i NUMBER;

BEGIN

FOR i IN nt.FIRST .. nt.LAST

LOOP

INSERT INTO nt_test(id, description) VALUES (i, nt(i));

END LOOP;

END nt_proc;

/

3- Create a test table, This is just for test purposes.

CREATE TABLE nt_test (id NUMBER, description VARCHAR2(30));

4- Create a module which defines the array of values

DECLARE

nt nt_type := nt_type(); -- nested table variable initialized to empty

BEGIN

nt := nt_type('Chester','Swindon','Corby','London','Swansea','Cardiff'); -- create your string of variables here

nt_proc(nt);

END;

/

SELECT * FROM nt_test;