Tuesday, September 7, 2010
Most commonly used JavaScript method or Function
****************************************************************************************************************************************
function sepcomma(number)
{
number=number+"";
for(ln=0;ln<number.length;ln++)
{
number = number.replace(",","");
}
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3* i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else
{
return number;
}
}
****************************************************************************************************************************************
function IntegerCheck(opt, obj1){
flag=0;
obj = obj1.value;
flag = obj1.value.indexOf(".");
if(opt > 0){
if(flag == -1)
{
if (!((event.keyCode >47 && event.keyCode < 58) || event.keyCode == 46))
event.keyCode=0;
}else{
if (event.keyCode <47 || event.keyCode > 57)
event.keyCode=0;
}
}else{
if (event.keyCode <47 || event.keyCode > 57)
event.keyCode=0;
}
}
****************************************************************************************************************************************
function textcounter(field,maxlen)
{
if(field.value.length > maxlen)
field.value = field.value.substring(0,maxlen);
}
****************************************************************************************************************************************
function movef(osr, odest){
var i = 0;
for(i = osr.options.length-1; i > -1; i--)
if(osr.options[i].selected){
odest.options[odest.options.length] = new Option(osr.options[i].text, osr.options[i].value);
osr.remove(i);
}
}
****************************************************************************************************************************************
function opencenterwindow(url)
{
var w=screen.width-80;
var h=screen.height-80;
window.open(url,'','height='+(parseInt(h)-parseInt(50))+',width='+(parseInt(w)-parseInt(50))+', resizable=1, scrollbars=1, top=0, left=0');
}
****************************************************************************************************************************************
function opendetailwindow(url)
{
var w=screen.width;
var h=screen.height-80;
window.open(url,'','height='+(parseInt(h)-parseInt(50))+',width='+(parseInt(w)-parseInt(50))+', status=1, resizable=0, scrollbars=1, top=0, left=0');
}
****************************************************************************************************************************************
function openmidyeardetailwindow(url)
{
var w=screen.width;
var h=screen.height-80;
window.open(url,'','height='+(parseInt(h)-parseInt(240))+',width='+(parseInt(w)-parseInt(50))+', status=1, resizable=0, scrollbars=1, top=0, left=0');
}
****************************************************************************************************************************************
function opencentermenuwindow(url) // with menu bar
{
var w=screen.width-80;
var h=screen.height-80;
window.open(url,'','height='+(parseInt(h)-parseInt(50))+',width='+(parseInt(w)-parseInt(50))+', menubar=1,resizable=1, scrollbars=1, top=0, left=0');
}
****************************************************************************************************************************************
function opencenterswindow(url)
{
window.open(url,'','height=300, width=650,resizable=no, scrollbars=0, top=0, left=0, status=0');
}
****************************************************************************************************************************************
function openplanhistorywindow(url) // with menu bar
{
var w=screen.width-150;
var h=screen.height-140;
window.open(url,'','height='+(parseInt(h)-parseInt(50))+',width='+(parseInt(w)-parseInt(50))+', resizable=0, scrollbars=1, status=1, top=0, left=0');
}
****************************************************************************************************************************************
function dispdate(dt){
if(dt.length < 1)
return;
if(dt.indexOf("-") < 0)
return;
if(dt.length > 10)
dt = dt.substring(0, 10);
var arr = dt.split("-");
return arr[2] + "/" + arr[1] + "/" + arr[0];
}
****************************************************************************************************************************************
function setLength(){
var objs = document.getElementsByTagName('TEXTAREA');
for(var i = 0; i < objs.length; i++){
if(objs[i].value.length == 0 || objs[i].id == "no")
continue;
while(objs[i].scrollHeight > objs[i].clientHeight)
objs[i].rows = objs[i].rows + 1;
//if(objs[i].id == "le" && objs[i].value.length < 80)
//{
//objs[i].cols = objs[i].value.length + 5;
//}
}
}
****************************************************************************************************************************************
function setLengthtarget(){
var objs = document.getElementsByTagName('TEXTAREA');
for(var i = 0; i < objs.length; i++){
if(objs[i].id == "idkrakpi")
{
while(objs[i].scrollHeight != objs[i].clientHeight)
objs[i].rows = objs[i].rows + 1;
}
}
}
****************************************************************************************************************************************
function f_open_window_max( aURL, aWinName )
{
var wOpen;
var sOptions;
sOptions ='menubar=no,scrollbars=yes,toolbar=no';
sOptions = sOptions + ',width=' + (screen.availWidth-10).toString();
sOptions = sOptions + ',height=' + (screen.availHeight-50).toString();
sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
sOptions = sOptions + ',resizable=no, status=1';
win=window.open(aURL,'', sOptions );
//alert(win);
}
****************************************************************************************************************************************
function closeall()
{
if(win !=null)
{
if( ! win.closed)
{
win.close();
}
}
window.close();
}
****************************************************************************************************************************************
function getConfirmation(msg)
{
if(confirm(msg))
return true;
else
return false;
}
function autochkselect(chkbxname,chkbxno, field)
{
var f = eval("document.all."+chkbxname);
if(field.value.length != 0)
{
if(chkbxno != -1)
f[chkbxno].checked = true;
else
f.checked = true;
}
}
function setTextArea(){
var _objs = document.getElementsByTagName('TEXTAREA');
var _objstxt = document.getElementsByTagName('INPUT');
for(var i = 0; i < _objs.length; i++){
if(_objs[i].id == "t1")
_objs[i].cols = screen.width*(6.68/100);
if(_objs[i].id == "t2")
_objs[i].cols = screen.width*(1.76/100);
if(_objs[i].id == "t3")
_objs[i].cols = screen.width*(4.50/100);
if(_objs[i].id == "t95")
_objs[i].cols = screen.width*(9.3/100);
if(_objs[i].id == "t80")
_objs[i].cols = screen.width*(7.81/100);
if(_objs[i].id == "t45")
_objs[i].cols = screen.width*(4.4/100);
if(_objs[i].id == "t40")
_objs[i].cols = screen.width*(4.0/100);
}
for(var i = 0; i < _objstxt.length; i++){
if(_objstxt[i].id == "tt105")
_objstxt[i].size = screen.width*(10.26/100);
if(_objstxt[i].id == "tt50")
_objstxt[i].size = screen.width*(4.89/100);
if(_objstxt[i].id == "tt5")
_objstxt[i].size = parseFloat(screen.width*(parseFloat(0.49/100)));
}
}
function openconfirmwindow(url)
{
var w=screen.width/2;
var h=screen.height/2;
window.open(url,'','height='+(parseInt(h)-parseInt(50))+',width='+(parseInt(w)-parseInt(50))+', resizable=1, scrollbars=1, top=0, left=0');
}
function f_open_window_max1( aURL, aWinName )
{
var wOpen;
var sOptions;
sOptions ='menubar=no,scrollbars=yes,toolbar=no';
sOptions = sOptions + ',width=' + (screen.availWidth-10).toString();
sOptions = sOptions + ',height=' + (screen.availHeight-50).toString();
sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
sOptions = sOptions + ',resizable=no, status=1';
win=window.open(aURL,aWinName, sOptions );
//alert(win);
}
function setWidthTextarea(){
var objs = document.getElementsByTagName('TEXTAREA');
var screenwidthmadeon=1024;
for(var i = 0; i < objs.length; i++){
var colsta=objs[i].cols;
objs[i].cols = screen.width*(colsta/screenwidthmadeon);
}
}
function setLengthTextarea(){
var objs = document.getElementsByTagName('TEXTAREA');
var screenwidthmadeon=768;
for(var i = 0; i < objs.length; i++){
while(objs[i].scrollHeight > objs[i].clientHeight){
objs[i].rows = objs[i].rows + 1;
}
}
}
function trim(strText) {
// this will get rid of leading spaces
while (strText.substring(0,1) == ' ')
strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
while (strText.substring(strText.length-1,strText.length) == ' ')
strText = strText.substring(0, strText.length-1);
return strText;
}
function showcomma(number2)
{
if (number2 =="NaN")
{
number2 = "0";
}
else
{
var number1 = "" + number2;
if (number1.indexOf(".") > 0)
{
var arr = number1.split(".");
if(arr.length > 1)
{
arr[1]= arr[1].substring(0,3);
number2= arr[0];
arr[0] = sepcomma(number2);
return arr[0]+"."+arr[1];
}
}
//else {return sepcomma(number2)+".0";}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment