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
}

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

Search for: add to a javascript array example


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

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

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

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

this trim only trims the front and the back


/* comment */

css conditional comments

Search for: css conditional comments

msdn string object


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;
}

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...


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

//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;
}

Javascript null

Search for: Javascript null


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";
}

string.toLowerCase()

Reference to the string object

javascript instance of an array

Search for: javascript instance of an array

Use this SOF link

Here is array reference


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

See notes on regular expressions here