String.prototype.trim = function() {

// skip leading and trailing whitespace
// and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function testCheckboxes()
{
	alert("hhhh");
	selRows = getSelectedCheckBoxValues(document.mainform,"my_checkbox",",");
	selRowsArray = selRows.split(",");
	if (selRowsArray.length == 0)
	{
		alert("No rows selected");
		return;
	}
	firstId = selRowsArray[0];

	alert("First selection before trim is:" + firstId + ":");
	
	firstId = firstId.trim();
	alert("First selection is:" + firstId + ":");
	
	//firstId now contains the key for the next page
}

satya - Friday, August 07, 2009 3:39:15 PM

Initialize a javascript array


var itemArray = [
    {name: "Social", value: "12345678"},
    {name: "cell1", value: "12345678"},
    {name: "cell2", value: "12345678"}
];

satya - Friday, August 07, 2009 4:27:27 PM

add to a javascript array example

Search for: add to a javascript array example

satya - Saturday, August 08, 2009 11:12:57 AM

You can add a new item to this array by reading off of an input field


var sarr="cell3:654321";
var arr = sarr.split(":");
var obj = {name:arr[0],value:arr[1]};

satya - Wednesday, June 22, 2011 3:10:31 PM

javascript array variable


var myarray = new Array();
myarray["first"]="hello";
myarray["second"]="hello2";

satya - Wednesday, June 22, 2011 3:22:04 PM

You can do this


var item1 = myarray["first"];
if (item1 != null)
{
   alert('not there');
}
else
{
   alert(item1);
}

satya - Wednesday, June 22, 2011 5:00:47 PM

jquery trim function


var s = "    hhhhh  ";
var s1 = $.trim(s);
alert(s1);

satya - Wednesday, June 22, 2011 5:01:19 PM

this trim only trims the front and the back

this trim only trims the front and the back

satya - Thursday, June 23, 2011 10:38:10 AM

comments in css


/* comment */

satya - Thursday, June 23, 2011 10:38:24 AM

css conditional comments

css conditional comments

Search for: css conditional comments

satya - Monday, August 08, 2011 10:27:54 AM

msdn string object

msdn string object

satya - Thursday, August 11, 2011 10:58:45 AM

You can get an array of elements belonging to a class


function gatherDivIdsWithAClassname(classname)
{
    var lDivIdArray = new Array();
    var divElementArray = $("." + classname);
    for(i=0;i<divElementArray.length;i++)
    {
        var curdiv = divElementArray[i];
        var curdivid = $(curdiv).attr("id");
        lDivIdArray[i]=curdivid;
    } 
    return lDivIdArray;
}

satya - Wednesday, August 17, 2011 12:09:55 PM

Here is a function to remove the first occ of a character from a string


function removeChar(s, c)
{
   var i = s.indexOf(c);
   if (i == -1)
   {
     return s;
   }
   //it exists
   var front = s.substring(0,i);
   var back = s.substring(i+1);
   return front + back;
}

may not be the most efficient...

satya - Wednesday, August 17, 2011 12:10:49 PM

Create a space between each character in a string


function spacethem(s)
{
  var ns = ""; 
  for (i=0; i<s.length; i++)
  {
     ns = ns.concat(s.charAt(i));
     ns = ns.concat(" ");
  }
  return ns;
}

satya - Wednesday, August 17, 2011 12:13:28 PM

extract letters from somestring(234): ome


//format: somesring(234)
//answer: ome (2nd, 3rd, and 4th letters)
function extractLetters(s)
{
  var i = s.indexOf('(');
  var j = s.indexOf(')');
  var letterNumbers = s.substring(i+1,j);
  
  var s1 = "";
  for (i=0;i<letterNumbers.length;i++)
  {
     var charIndex = letterNumbers.charAt(i);
     var nCharIndex = parseInt(charIndex);
     var c = s.charAt(nCharIndex-1);
     s1= s1.concat(c);
  }
  return s1;
}

satya - Saturday, February 25, 2012 9:34:21 AM

Javascript null

Javascript null

Search for: Javascript null

satya - Sat May 05 2012 13:34:06 GMT-0400 (Eastern Daylight Time)

here is an example of tokenization


function showPost()
{
   var fieldSpec="{{f_field_names}}";
   var fieldList = fieldSpec.split("|");
   
   var fieldSpecPost = "";
   var first = true;
   for(i=0;i<fieldList.length;i++)
   {
       var indFieldSpec = fieldList[i];
       if (first == true)
       {
         first=false;
         fieldSpecPost += getSamplePostForFieldSpec(indFieldSpec);
      }
      else
      {
         fieldSpecPost += "&";
         fieldSpecPost += getSamplePostForFieldSpec(indFieldSpec);
      }
   }
   alert(fieldSpecPost);
}
function getSamplePostForFieldSpec(fieldSpec)
{
   var fieldSpecParts = fieldSpec.split(",");
   var fieldName = fieldSpecParts[0];
   var fieldType = fieldSpecParts[1];
   if (fieldType.indexOf("num") >= 0)
   {
      //it is a number
      return fieldName + "=10";
   }
   if (fieldType.indexOf("date") >= 0)
   {
      //it is a date
      return fieldName + "=04/15/2012";
   }
   return fieldName + "=" + fieldName + " value";
}

satya - Fri Oct 12 2012 13:21:00 GMT-0400 (Eastern Daylight Time)

string.toLowerCase()

string.toLowerCase()

satya - Fri Oct 12 2012 13:21:54 GMT-0400 (Eastern Daylight Time)

Reference to the string object

Reference to the string object

satya - 6/17/2013 3:58:07 PM

javascript instance of an array

javascript instance of an array

Search for: javascript instance of an array

satya - 6/17/2013 4:01:41 PM

Use this SOF link

Use this SOF link

satya - 5/2/2014 11:03:52 AM

Here is array reference

Here is array reference

satya - 5/2/2014 11:05:59 AM

You can do push to add an object to an array


var a = new Array();
var o = {field1:"value", field2: "value"};
a.push(o);

satya - 5/24/2014 12:11:13 PM

See notes on regular expressions here

See notes on regular expressions here