Monday, November 30, 2009
Block user from right clicking your web site
{
if (navigator.appName == 'Netscape' &&(e.which == 3 e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&(event.button == 2 event.button == 3))
{
alert("Please don't right click , Thanks Prateek!!");
return false;
}
return true;
}
document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
Thursday, October 22, 2009
Get CheckBox Text
<asp:CheckBox runat="server" ID="chkFavorites"Text="Show Favorites" Checked="true" /><br/>
/http://forums.asp.net/p/1018339/1373760.aspx
function getCheckBoxText(CheckBoxId)
{
var checkbox = document.getElementById(CheckBoxId);
//alert(checkbox.nextSibling);
//alert(checkbox.nextSibling.nodeType);
// alert(checkbox.nextSibling.nodeName);
//alert(checkbox.nextSibling.innerHTML);
if(checkbox.checked == true )//&& checkbox.nextSibling != null)
{
var label = checkbox.nextSibling;
//alert(label.innerText);
alert(label.innerHTML);
}
}
{
var list = "";
var idModifier = 0;
var checkbox = document.getElementById(("ctl00_ContentPlaceHolder1_lstFacility_" +
idModifier));
while(checkbox != null)
{
if(checkbox.checked == true)// && checkbox.nextSibling != null)
{
var label = checkbox.nextSibling;
list += label.innerText + ", ";
}
checkbox = document.getElementById(("ctl00_ContentPlaceHolder1_lstFacility_" +
(++idModifier).toString()));
}
// here you should remove any trailing
commas.
}
http://simonwillison.net/2003/Aug/11/documentAll/
document.all.length
is not support in firefox
for(i = 0; i < document.all.length; i++)
{
if
(document.all(i).tagName=="label")
{
document.getElementById(
'<%=
lblShowFavorite.ClientID %>').innerHTML = "<b>" +
document.all(i).innerText +" : " + "</b>" +
document.getElementById('<%=chkShowFav.ClientID%>').checked;
break;
}
}
Friday, September 18, 2009
Table
document.getElementById('myTable').border="10";
document.getElementById('myTable').cellPadding="15";
document.getElementById('myTable').cellSpacing="15";
document.getElementById('myTable').frame="above";
document.getElementById('myTable').frame="below";
document.getElementById('myTable').rules="rows";
document.getElementById('myTable').rules="cols";
document.getElementById('myTable').rules="none";
document.getElementById('tr2').align="left";
document.getElementById('tr2').vAlign="top";
alert(document.getElementById('myTable').rows[0].innerHTML);
function
valignCell()
{
var
x=document.getElementById('myTable').rows[0].cells;
x[0].vAlign="bottom";
}
function
changeContent()
{
var
x=document.getElementById('myTable').rows[0].cells;
x[0].innerHTML="NEW CONTENT";
}
function
setColSpan()
{
var
x=document.getElementById('myTable').rows[0].cells;
x[0].colSpan="2";
x[1].colSpan="6";
}
function
cell()
{
var
x=document.getElementById('myTable').rows[0].cells;
alert(x[0].innerHTML);
}
function
createCaption()
{
var
x=document.getElementById('myTable').createCaption();
x.innerHTML="My table caption";
}
Delete
rows in a table
function
deleteRow(r)
{
var
i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
<table
id="myTable" border="1">
<tr>
<td>Row 1</td>
<td><input type="button"
value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
<td>Row 2</td>
<td><input type="button"
value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
<td>Row 3</td>
<td><input type="button"
value="Delete" onclick="deleteRow(this)"></td>
</tr>
</table>
Add rows
to a table
function
insRow()
{
var
x=document.getElementById('myTable').insertRow(0);
var
y=x.insertCell(0);
var
z=x.insertCell(1);
y.innerHTML="NEW CELL1";
z.innerHTML="NEW CELL2";
}
Add cells
to a table row
function
insCell()
{
var
x=document.getElementById('myTable').insertCell(0);
x.innerHTML="John";
}
Frame
<html>
<frameset rows="50%,50%">
<frame id="leftFrame" src="frame_noresize.htm">
<frame id="rightFrame" src="frame_a.htm">
</frameset>
<frameset cols="50%,50%">
<frame id="leftFrame" src="frame_noresize.htm">
<frame id="rightFrame" src="frame_a.htm">
</frameset>
</html>
do it from child pages
parent.document.getElementById("rightFrame").noResize=false;
parent.document.getElementById("rightFrame").scrolling="yes";
parent.document.getElementById("rightFrame").src=http://google.com;
Break out of a frame
function breakout()
{
if (window.top!=window.self)
{
window.top.location="tryjs_breakout.htm";
}
}
Automatically jumps to the next field
This script automatically jumps to the next field when a field's maxlength has been reached:
<form id="myForm">
<input size="3" tabindex="1" maxlength="3" onkeyup="checkLen(this,this.value)">
<input size="2" tabindex="2" maxlength="2" onkeyup="checkLen(this,this.value)">
<input size="3" tabindex="3" maxlength="3" onkeyup="checkLen(this,this.value)">
</form>
function checkLen(x,y)
{
if (y.length==x.maxLength)
{
var next=x.tabIndex;
if (next<document.getElementById("myForm").length)
{
document.getElementById("myForm").elements[next].focus();
}
}
}
select
<select id="mySelect" onchange="favBrowser()">
<option>Internet Explorer</option>
<option>Netscape</option>
<option>Opera</option>
</select>
function favBrowser()
{
var mylist=document.getElementById("mySelect");
document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
}
alert(document.getElementById("mySelect").selectedIndex);
alert(document.getElementById("mySelect").length);
document.getElementById("mySelect").size=4;
document.getElementById("mySelect").multiple=true;
function getOptions()
{
var x=document.getElementById("mySelect");
txt="All options: "
for (i=0;i<x.length;i++)
{
txt=txt + "\n" + x.options[i].text;
}
alert(txt);
}
Remove options from a dropdown list
function removeOption()
{
var x=document.getElementById("mySelect");
x.remove(x.selectedIndex);
}
<select id="menu" onchange="go()">
<option>--Select a page--</option>
<option value="http://senthilmcan.blogspot.com">Senthil</option>
<option value="http://www.microsoft.com">Microsoft</option>
<option value="http://senthilmcan-clientscript.blogspot.com">Clientscript</option>
</select>
function go()
{
window.location=document.getElementById("menu").value;
}