One more step towards technology

Update a parent window from a child – Java Script

In Fun with technology on July 9, 2010 at 7:42 am

Parent Window HTML

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script language=”javascript”>
function parent_call()
{
alert(“I am your parent”);
}

function openme()
{
window.open (“file2.html”,”mywindow”,’height=200, width=200, resizable=no, scrollbars=no,toolbar=no,location=yes, directories=no, status=no, menubar=no, copyhistory=yes’);
}
</script>
</head>

<body>
<input type=”text” id=”parent_text” />
<input type=”button” value=”Open Child Window” onclick=”openme()” />
</body>
</html>

Child Window HTML

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script language=”Javascript” type=”text/javascript”>

function updateParent_text()
{
window.opener.document.getElementById(“parent_text”).value = document.getElementById(“TextBox1″).value;
//return false;
}

function call_parent()
{
window.opener.parent_call();
//return false;
}
</script>
</head>

<body>
<input type=”text” id=”TextBox1″ />
<input type=”button” value=”Update Parent Text” onclick=”updateParent_text()” />
<input type=”button” value=”Call Parent Window” onclick=”call_parent()” />

</body>
</html>

Cookie in JavaScript

In Uncategorized on July 6, 2010 at 12:57 pm

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body style=”font-size:12px;font-family:Arial, Helvetica, sans-serif;”>
Cookie Value
<input id=”c-value” type=”text” />
<br />
<br />
<input type=”button” value=”create” onclick=”create()” />
<input type=”button” value=”update” onclick=”update()” />
<input type=”button” value=”remove” onclick=”remove()” />
<input type=”button” value=”check” onclick=”check()” />
<script language=”javascript”>
function create()
{
document.cookie =’Cookie_value = ‘+ document.getElementById(“c-value”).value +’; path=/’;
}
function remove()
{
document.cookie =’Cookie_value = ‘+ document.getElementById(“c-value”).value +’;expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/’; // expires=old date;
}
function update()
{
document.cookie =’Cookie_value = ‘+ document.getElementById(“c-value”).value +’;path=/’; // expires=old date;
}
function check()
{
if((document.cookie).indexOf(“Cookie_value=”)>=0)
{
var t=document.cookie.split(‘;’);
alert((t[t.length – 1].split(‘=’))[(t[t.length – 1].split(‘=’)).length – 1]);
}
else
alert(“No Cookie”);
}
</script>
</body>
</html>

Max Character Limit For Text Area

In Fun with technology on July 2, 2010 at 9:59 am

<body style=”font-family:Arial, Helvetica, sans-serif; font-size:12px;”>
<div style=”width:600px;”><strong>Enter Your Status</strong>
<textarea onkeyup=”char_count()” style=”width:600px; height:400px;” id=”text_area”></textarea>
</div>
<div style=”clear:both;”></div>
<div><strong>Char Count :</strong> <span id=”count”></span></div>
<script language=”javascript”>
document.getElementById(“count”).innerHTML = 30;
function char_count()
{
var t=(document.getElementById(“text_area”).value).length;
if(t>30)
{
document.getElementById(“count”).innerHTML = “-” + (t-30);
document.getElementById(“count”).style.color=”red”;
}
else
{
document.getElementById(“count”).innerHTML = (30 – t);
document.getElementById(“count”).style.color=”black”;
}
}
</script>
</body>