JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods

HOW TO DISPLAY DYNAMIC TEXT ON IMAGE ONMOUSEOVER

I needed to do a small javascript that will change text dynamically upon onmouseover of an image for a star rating on one of my sites. I came up with the solution as the demo below. Hover over the stars to see the text dynamically change:



              
Default text


Put the following code in between the <head> and </head>tags:

<script type="text/javascript">
function dis(num)
{
var num;

if(num==1)
{
document.getElementById('test').innerHTML = 'Poor';
}

if(num==2)
{
document.getElementById('test').innerHTML = 'Fair';
}

if(num==3)
{
document.getElementById('test').innerHTML = 'Good';
}

if(num==4)
{
document.getElementById('test').innerHTML = 'Very Good';
}

if(num==5)
{
document.getElementById('test').innerHTML = 'Excellent';
}

}
function def()
{
document.getElementById('test').innerHTML = 'Default text';
}

</script>

Put the following code in the body section of your page:

<a href="#" onmouseover="dis(1);" onmouseout="def();" ><img src='stars.png' border='0' /></a>  
<a href="#" onmouseover="dis(2);" onmouseout="def();" ><img src='stars.png' border='0' /></a>  
<a href="#" onmouseover="dis(3);" onmouseout="def();" ><img src='stars.png' border='0' /></a>  
<a href="#" onmouseover="dis(4);" onmouseout="def();" ><img src='stars.png' border='0' /></a>  
<a href="#" onmouseover="dis(5);" onmouseout="def();" ><img src='stars.png' border='0' /></a>  



Home | Privacy Policy | Terms Of Use | Contact Us