How to calculate age from 2 dates in Javascript

Below javascript function will calculate age from 2 date values. Remember date values should be in DD/MM/YYYY format. Similarly we can also use the same function to calculate Age difference function CalculateAge(TodaysDate,NewDate) // Pass date values in DD/MM/YYYY format { var day1 = parseInt(TodaysDate.substring(0,2),10); var mon1 = parseInt(TodaysDate.substring(3,5),10); var yr1 = parseInt(TodaysDate.substring(6,10),10); var day2 =…

Details

How to restrict Special Characters in Javascript

checkSpcialChar function will restrict the special characters in the input box. We need to pass the event as a parameter for that function. We also change keycodes to allow or disallow more keys. <html> <head> <script type=”text/javascript”> function checkSpcialChar(event){ if(!((event.keyCode >= 65) && (event.keyCode <= 90) || (event.keyCode >= 97) && (event.keyCode <= 122) ||…

Details

How to clear Drop Down \ Combo \ Select box values in javascript

Use the below code to empty the combo box in JavaScript.

document.getElementById(“ComboBoxName”).options.length=0;

Example

<html>
<head>
<script type="text/javascript">
  function clearCombo()
  {
     document.getElementById('drpFruits').options.length=0;
  }
</script>
</head>
<body>
<form id="form1">
<div>
<select name="drpFruits" id="drpFruits">
<option value="A">Apple</option>
<option value="O">Orange</option>
<option value="B">Banana</option>
<option value="S">Strawberry</option>
</select>
<input type="Button" name="clear" value="clear" onclick="clearCombo();">
</div>
</form>
</body>
</html>

How to read a Excel file in Javascript using ActiveX

The following code will help you to read a Excel File and show it has table format in HTML <html> <body onload=”GetData();”> <div id=”ExcelContent”> </div> </body> <script type=”text/javascript”> function GetData() { var excel = new ActiveXObject(“Excel.Application”); var excel_file = excel.Workbooks.Open(“H:/sample_Codes/sample.xls”); var excel_sheet = excel.Worksheets(“Sheet1″); var totalColCount=excel_sheet.UsedRange.Columns.Count; var totalRowCount = excel_sheet.UsedRange.Rows.Count; var htmlStr=”<table>”; for(i=0;i<totalRowCount;i++) { htmlStr…

Details

Function to restrict only numbers in textbox using javascript

<html>
 <head>
 <script type="text/javascript">
 function validate(key)
 {
     var keycode = (key.which) ? key.which : key.keyCode;
     var phn = document.getElementById('txtPhn');
     if (!(keycode==8 || keycode==46)&&(keycode < 48 || keycode > 57))
         return false;
     else
         return true;
 }
 </script>
 </head>
 <body>
 <form id="form1">
     <div>
         <input type="text" ID="txtPhn" onkeypress="return validate(event)"></input>
     </div>
 </form>
 </body>
</html>

Enabling/Disabling/Checking/Unchecking Checkbox in javascript

<html> <head> <script languate=”text/javascript”> function Operation(opr) { switch(opr) { case ‘enable’ : document.getElementById(‘checkbox1′).disabled=false; break; case ‘disable’ : document.getElementById(‘checkbox1′).disabled=true; break; case ‘check’ : document.getElementById(‘checkbox1′).checked=true; break; case ‘uncheck’ : document.getElementById(‘checkbox1′).checked=false; break; } } </script> </head> <body> <form name=”codefloor”> <input type=”checkbox” name=”checkbox1″ id=”checkbox1″/> <input type=”button” name=”button1″ id=”button1″ value=”Enable” onclick=”Operation(‘enable’);”/> <input type=”button” name=”button2″ id=”button2″ value=”Disable” onclick=”Operation(‘disable’);”/> <input type=”button” name=”button3″…

Details

how to create folder in javascript

<html>
<body>

<script>
  //Create Folder: "c:\testfolder" in specified location

  function createnewfolder()
  {
    var myFSOObject, newfolderObj;
    myFSOObject = new ActiveXObject("Scripting.FileSystemObject");
    newfolderObj = myFSOObject.CreateFolder ("c:\\newtmp\\");
  }
</script>

  <form name="myFormTest">
    <input type="Button" value="Click to Create New Folder" onClick='createnewfolder()'>
  </form>

</body>
</html>