Monday, May 31, 2010

Thursday, May 27, 2010

Round of a decimal value using Javascript

Function to round of the decimal value is shown below.

//Example to fix a decimal value to 2 decimal places when it has number of decimal places
var num = 234.8766;
var result = num.toFixed(2); //The result will be 234.88;

//to fix to a 2 decimal values if a number has no decimal values

var num = 8769;
var result = num.toFixed(2); //The result will be 8769.00;





Sony Cyber-shot DSC-T90 12.1 MP Digital Camera with 4x Optical Zoom and Super Steady Shot Image Stabilization (Silver)Sony Cybershot DSC-W220 12.1MP Digital Camera with 4x Optical Zoom with Super Steady Shot Image Stabilization (Black)  Sony Cyber-shot DSC-HX1 - Digital camera - compact - 9.1 Mpix - optical zoom: 20 x - supported memory: MS Duo, MS PRO Duo, MS PRO-HG Duo  Sony Cyber-shot DSC-W230 12 MP Digital Camera with 4x Optical Zoom and Super Steady Shot Image Stabilization (Dark Red)
Sony 4 GB Memory Stick PRO Duo Flash Memory Card MSMT4G   Sony LCSCSQ/B Soft Carrying Case for Sony T, W, and N Series Digital Cameras (Black)  Replacement Sony NP-BG1 Equivalent LithiumIon Camera Battery For SONY DSC-H9/DSC-H7/DSC-H3 /DSC-H50/DSC-W30/DSC-W35/DSC-W50/DSC-W55/DSC-W70Sony NPBN1 Rechargeable Battery Pack  

Sunday, May 23, 2010

How to Print a part of webpage using Javascript

<html>
<head>
<title>Print a part of HTML or Webpage using Javascript</title>
<script type="text/javascript">
function printDiv()
{
   var divToPrint=document.getEelementById('areaToPrint');
  newWin= window.open("");
  newWin.document.write(divToPrint.outerHTML);
  newWin.print();
  newWin.close();
}

</script>
</head>
<body>

<div id="areaToPrint">
The text you want to print or the content you want to print
</div>
</body>
</html>

---> The Javascript function can be called using an ANCHOR link or a onClickevent for a button or else in body onload function.

Friday, May 7, 2010

To Remove Suggestions for a textbox

Removing the suggestions or disable the autocompletion of a textbox. We need to add the tag in the textbox as shown below.

<input type='text' name='txtbox' autocomplete='off'>

or can be added in the form tag

<form autocomplete='off'>

Tuesday, May 4, 2010

How to check & uncheck all the checkboxes in a form

  The below function is used to check all the checkboxes & uncheck them in a form

checked = false;
function checkedAll () {
    if (checked == false){checked = true}else{checked = false}
             for (var i = 0; i < document.getElementById('myform').elements.length; i++) {
                   document.getElementById('myform').elements[i].checked = checked;
                  }
}

Monday, May 3, 2010

Setting a Website as Homepage in IE using Javascript

<form>
<input type="button" value="Make This Site Your Home Page" onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage('http://anilkajadoo.blogspot.com');">
</form>

****This works only in IE browser......