Patelkiranat1983’s Weblog

Just another WordPress.com weblog

IMP Javascripts Functions

* Description:
* check on key down whether the value is numeric or not.
*
function numbersonly(evt) {

evt = (evt) ? evt: window.event;
// Detect issuing element.
var srcElt = (evt.target) ? evt.target : evt.srcElement;

var unicode = evt.charCode? evt.charCode : evt.keyCode;

if (unicode != 8) { //if the key isn’t the backspace key (which we should allow)
if (unicode < 48 || unicode > 57) { //if not a number
srcElt.value = ”;
return false //disable key press
}
}

return true;
}// End function: numbersonly.
  /*
* Name:
* limitlength
*/
function limitlength(obj, length) {

var maxlength = length;

if (obj.value.length > maxlength) {
obj.value = obj.value.substring(0, maxlength);
}
}//End of function limitlength
  /*
* Description:
* Get the javascript object. useful when some times explore not support document.getElementById()
* It is not used in this file yet. but if required then we can used this function to create the javascript object.
*/
function getElement(obj, d) {
var i,x;

if(!d) d=document;

if(!(x=d[obj])&&d.all)
x=d.all[obj];

for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][obj];

for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=GetElement(obj,d.layers[i].document);

if(!x && document.getElementById)
x=document.getElementById(obj);

return x;
}// End function: getElement.
  /*
* Description:
* Convert a first character of string as capital letter.
*
*/
function ucFirst(strArg) {
var charFirst = strArg.charAt(0);

if (parseInt(strArg.length)==1){
return charFirst.toUpperCase();
}
else
{
return charFirst.toUpperCase() + strArg.slice(1).toLowerCase();
}
}// End function: ucFirst.
  /*
* Description:
* This return the whole string ## seperator with the set of property on passed control.
* It is used for debugging purpose so, we can see which property is set to the particular object.
* but for style property it is working fine in mozill but display null value in internet explorer
*/
function getAttributes(countrolObj) {
var propartyValues = ”;

//it reads the tag one by one elements and create the corosponding hidden varaible in array……
for(var i=0;i<countrolObj.attributes.length;i++) {
if(countrolObj.attributes[i].specified) {
propartyValues += countrolObj.attributes[i].nodeName + “=” + countrolObj.attributes[i].nodeValue + ‘##’;
}
}

if(propartyValues) {
alert(‘All property with ## seperator ==> ‘);
alert(propartyValues);
}

return propartyValues;
} // End function: getAttributes.
12:44 PM /*
* Description:
* For checking the variable is object type or not.
*
*/
function isObject(a) {
return (a && typeof a == ‘object’) || isFunction(a);
} // End function: isObject.
function isFunction(a) {
return typeof a == ‘function’;
} // End function: isFunction.
  /*
* Description:
* Return the given text with the following HTML entities escaped:
* ampersand, single-quote, double-quote, angled brackets.
*/
function htmlEntitizeText(text) {
// Make sure ampersands are replaced FIRST, otherwise the ampersands of
// the escaped entities will themselves be escaped.
text = text.replace(/\&/g, ‘&’);
text = text.replace(/\”/g, ‘”‘);
// The standard “&apos;” is broken for some versions
// of IE. Use numeric entity replacement instead.
text = text.replace(/\’/g, ”’);
text = text.replace(/\</g, ‘<’);
text = text.replace(/\>/g, ‘>’);

return text;
} // End function: htmlEntitizeText.

function textToHtmlEntities(text) {
// Make sure ampersands are replaced FIRST, otherwise the ampersands of
// the escaped entities will themselves be escaped.
text = text.replace(/\&/g, ‘&’);
text = text.replace(/\”/g, ‘”‘);
// The standard “&apos;” is broken for some versions
// of IE. Use numeric entity replacement instead.
text = text.replace(/\’/g, “‘”);
text = text.replace(/\</g, ‘<’);
text = text.replace(/\>/g, ‘>’);

return text;
} // End function: htmlEntitizeText.
  *************

August 31, 2007 - Posted by patelkiranat1983 | Uncategorized | | No Comments Yet

No comments yet.

Leave a comment