Posts

Showing posts from February, 2012

substr in javascript

Syntax string .substr(start,length) Parameter Description start Required. The index where to start the extraction. First character is at index 0 length Optional. The number of characters to extract. If omitted, it extracts the rest of the string Example Example Extract characters from a string: The output of the code above will be: v vR

how to get xmldoc in a string

put this line wherever u needed to do this. var string = (new XMLSerializer()).serializeToString(xmlDoc);

how to load a string into dom

//------------- load a string into dom -------- //@param: string to be loaded //@return: xml dom document function dom_load(string) { //alert("dom_load"); if (window.DOMParser)   {   parser=new DOMParser();   xmlDoc=parser.parseFromString(string,"text/xml");   }   else // Internet Explorer   {   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");   xmlDoc.async="false";   xmlDoc.loadXML(string);     } }

angle between two points in javascript

//--------- to get angle between two points --------- //---param--- //@x1,x2,y1,y2 : cordinates of 2 points //@return: theta(value in degrees) function getTanTheta(x1,y1,x2,y2) { var y = eval(y2)-eval(y1); var x = eval(x2)-eval(x1); if(y < 0) { y = -y;} if(x < 0) { x = -x;} //alert(y+'  '+x); var tanTheta = y/x; if(tanTheta < 0) { tanTheta = -x;} tanTheta = roundNumber(tanTheta,3); //alert(tanTheta); return tanTheta; }

Round number in javascript

//------- Rounding in javascript -------- //@param: Number, length to round //@return: Rounded number function roundNumber(rnum, rlength)  { // Arguments: number to round, number of decimal places   var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);     newNumber = parseFloat(newnumber); // Output the result to the form field (change for your purposes)     return newNumber; }