Javascript


We can use the below code to show an image in the mouseover of an another image.

<img src=”images/cvv2_small.gif” style=”vertical-align:top;cursor:pointer;” border=”0″ onmouseover=”ShowBigImage();” onmouseout=”ShowDefaultImage();” />

<div id=”LargeImageDiv” style=”position:absolute;z-index:100″></div>

<script type=”text/javascript”>

function ShowBigImage()
{
document.getElementById(“LargeImageDiv”).innerHTML = “<img src=’images/largecard.gif’>”;
}

function ShowDefaultImage()
{
document.getElementById(“LargeImageDiv”).innerHTML = “”;
}

</script>

We can add the following script to include the “Firebug” in any browser.

<script type=’text/javascript’ src=’http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js‘></script>

function CompareDateFrom(ptr1,ptr2)
{
if(ptr2.value != ”)
{
d1 = new Date(ptr1.value);
d2 = new Date(ptr2.value);
if(d1 > d2)
{
msg = “From cannot be greater than To!”;
if(msg)
{
alert(msg);
ptr1.value = “”;
return false;
}
}
}
}

<input type=”text” name=”date_from” size=”7″ onblur=”javascript:check_date(this);CompareDateFrom (this,document.formname.date_to);”…….>

<input type=”text” name=”date_to” size=”7″….>

Sometimes focus on a specific form element will not work in Firefox.
To make it work in Firefox, we can use settimeout function.

The function setTimeout() executes the javascript code after a specified time interval.
Syntax : setTimeout(“javascript statement”,milliseconds);

The first parameter of setTimeout() is a string that can contain any JavaScript statement.
The second parameter indicates how many milliseconds from now we want to execute the first parameter.

To focus on a particular form element, we can give the following statement :

settimeout(function() { ptr.focus();} , 0) where ‘ptr’ is the form element.