Jump to content

Working with mouseover


Da Loup

Recommended Posts

I'm still grasping concepts of Javascript, and I have a personal project going on that I need the mouseover function for, but I can't seem to get it to work. It basically runs down like this, I have a table (In html it'll look like this:<table border="1" width="100%" id="table1"> <tr name="topleft"> <td name="intopleft">Text A</td> <td name="right" rowspan="2">Result A/B</td> </tr> <tr name="bottomleft"> <td name="inbottleft">Text B</td> </tr></table>) Note I'm also not very fluid in html, but stated above this is a personal project.The thing is, I want to use javascript so that I can make it to where when I mouse over the table that has Text A on it, I get Result A, and when I mouse over Table B I get Result B. For instance, if Table A says "Good Morning", when I mouse over that text, the Result A would say "Yes it is a good morning". and if I moused over Table B, which would say "Good Night", then Result B would replace Result A with "I'm tired, going to go to bed. Good night". Both of these results should occur in '<td name="right" rowspan="2>'I know this might be simple if directly explained, but I can't find a direct explanation on how to do this. Your help is much appreciated!

Link to comment
Share on other sites

Here's a sample code.

<html><head><script type="text/javascript">function moseOver(which) { //yes, moseOver. No need to complicate it with 'mouse' //Ok, this checks whether the which variable says it's morning or night//(1 or 0)if(which=1) {  //set the box to say "Yes its a good morning"  document.getElementById("right").innerHTML="Yes it is a good morning."}else {  //set the box to say "I'm tired, going to go to bed. Good night"  document.getElementById("right").innerHTML="I'm tired, going to go to bed. Good night"}}/*The following function sets the box to blank when the user takes his mouse off either one of the set tables (a and b). You can remove the "onmouseout" events of the tables if you like. */function moseOut() {document.getElementById("right").innerHTML="";}</script></head><body><table border="1" width="100%" id="table1"><tr id="topleft"><td id="intopleft" onmouseover="moseOver(1)" onmouseout="moseOut()">Text A</td><td id="right" rowspan="2">Result A/B</td></tr><tr id="bottomleft"><td id="inbottleft" onmouseover="moseOver(0)" onmouseout="moseOut()">Text B</td></tr></table></body>

Try that?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...