++++++ add element ++++++++

function addElement() {
  var ni = document.getElementById(‘myDiv’);
  var numi = document.getElementById(‘theValue’);
  var num = (document.getElementById(‘theValue’).value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement(‘div’);
  var divIdName = ‘my’+num+’Div’;
  newdiv.setAttribute(‘id’,divIdName);
  newdiv.innerHTML = ‘Element Number ‘+num+’ has been added! <a href=’#’ onclick=’removeElement(‘+divIdName+’)'>Remove the div “‘+divIdName+’”</a>’;
  ni.appendChild(newdiv);
}

 ++++++ remove element ++++++++

 function removeElement(divNum) {
  var d = document.getElementById(‘myDiv’);
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

detect plugin

กรกฎาคม 10, 2007

//This script detects the following:
//Flash
//Windows Media Player
//Java
//Shockwave
//RealPlayer
//QuickTime
//Acrobat Reader
//SVG Viewer
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") +
detectIE("SWCtl.SWCtl.1","Shockwave Director") +
detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") +
detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") +
detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") +
detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") +
detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
nse = "";
for (var i=0;i<navigator.mimeTypes.length;i++)
nse += navigator.mimeTypes[i].type.toLowerCase();
pluginlist = detectNS("image/svg-xml","SVG Viewer") +
detectNS("application/x-director","Shockwave Director") +
detectNS("application/x-shockwave-flash","Shockwave Flash") +
detectNS("audio/x-pn-realaudio-plugin","RealPlayer") +
detectNS("video/quicktime","QuickTime") +
detectNS("application/x-mplayer2","Windows Media Player") +
detectNS("application/pdf","Acrobat Reader");
}
function detectIE(ClassID,name)
{ result = false;
document.write('<SCRIPT LANGUAGE=VBScript>
n on error resume next n
result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>n');
if (result) return name+','; else return ''; }
function detectNS(ClassID,name) {
n = "";
if (nse.indexOf(ClassID) != -1)
if (navigator.mimeTypes[ClassID].enabledPlugin != null)
n = name+","; return n; }  pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0)
pluginlist = pluginlist.substring(0,pluginlist.length-1);
//SAMPLE USAGE- detect "Flash" //if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")

clipbord

กรกฎาคม 9, 2007

function CutToClipboard()

{

   CutTxt = document.selection.createRange();

   CutTxt.execCommand(”Cut”);

}

function CopyToClipboard()

{

   CopiedTxt = document.selection.createRange();

   CopiedTxt.execCommand(”Copy”);

}

function PasteFromClipboard()

{

   document.Form1.txtArea.focus();

   PastedText = document.Form1.txtArea.createTextRange();

   PastedText.execCommand(”Paste”);

}

</script>

Simple Calendar

มิถุนายน 27, 2007

<HTML>
<BODY>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
var week = new Array(“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”);
var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var today = new Date();
var month = today.getMonth();
var day = today.getDay();
var dayN = today.getDate();
var days = monthdays[month];
if (month == 1) {
  var year = today.getYear();
  if (year%4 == 0) days = 29;
}
document.write(“<table border=’0′ cellspacing=’0′ cellpadding=’0′>”);
document.write(“<tr>”);
for (var i=0; i<7; i++) {
  document.write(“<td width=’30′ height=’30′>”);
  document.write(“<div align=’center’>” + week[i] + “</div>”);
  document.write(“</td>”);
}
document.write(“</tr>”);
var jumped = 0;
var inserted = 1;
var start = day – dayN%7 + 1;
if (start < 0) start += 7;
var weeks = parseInt((start + days)/7);
if ((start + days)%7 != 0) weeks++;
for (var i=weeks; i>0; i–) {
  document.write(“<tr>”);
  for (var j=7; j>0; j–) {
    document.write(“<td>”);
    if (jumped<start || inserted>days) {
      document.write(“<div align=’center’></div>”);
      jumped++;
    }
    else {
      if (inserted == dayN) document.write(“<div align=’center’>[" + inserted + "]</div>”);
      else document.write(“<div align=’center’>” + inserted + “</div>”);
      inserted++;
    }
    document.write(“</td>”)
  }
  document.write(“</tr>”);
}
document.write(“</table>”);
//  End –>
</script>
</BODY>
</HTML>

file size

มิถุนายน 25, 2007

วิธีเข้าถึงขนาดของไฟล์ที่ input type=”file” โดยใช้ javascript +ActiveX
<html>
<head>
<script language=”JavaScript”>
function A()
{
var oas = new ActiveXObject(“Scripting.FileSystemObject”);
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + ” bytes”);
}
</script>
</head>
<body>
<form name=”a”>
<input type=”file” name=”b”>
<input type=”button” name=”c” value=”SIZE” onClick=”A();”>
</form>
</body>
</html>