473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Issue with a variable setting itself to the page?

Hey, I've got another issue, although my last one was never worked through... I'm pretty sure this is easy to solve. I've got a little javascript code and I would like to have it be able to fire an onmouseout without defining it explicitly within the HTML tags.

I added in a little code to tell me what the variable itemId was set to when it couldn't locate the object in the page. It came out with the location of the page instead of the variable that I had passed to the function originally (and then again inside a function that calls itself).

The focus is on lines 15 - 31.

-----> Demo

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
<!--
function d2h(d) // Decimal to Hex
{
return d.toString(16);
}
function h2d(h) // Hex to Decimal
{
return parseInt(h,16);
}
function start(itemId)
{
var object = document.getElementById(itemId);
if(!object)
{
document.write("Error, itemId has been set to: "+itemId);
}
if(true) //object.onmouseover)
{
object.innerHTML = "Shiney Link! (Mouse: Over)";
setTimeout("start("+itemId+"); ", (1000));
}
else
{
object.innerHTML = "Shiney Link! (Mouse: Off)";
}
}
function restore(id)
{
// Nothing Yet
}
// -->
</script>
<title>Shiney Link!</title>
</head>

<body>
We are testing the "Shiney Link!" JavaScript program below!<br />
To test it, just simply move your mouse over the link.<br />
In the future we will work on making images, and tables do the same.<br />
<br />
<a href="./" id="shiney" onmouseover="start(this.id); ">Shiney Link! (Mouse: Off)</a>
</body>
</html>[/HTML]
Dec 14 '07 #1
4 1748
Dasty
101 Expert 100+
I did not follow the purpose of your script. But you got error (typo?). in your code. you are sending id to your function as string value. But in setTimeout you forgot to add quotation marks:

Expand|Select|Wrap|Line Numbers
  1. setTimeout("start('"+itemId+"'); ", (1000));
But your code will end up in infinity loop of calling start() for your item id (every 1 sec). But it's maybe because the code is not finished yet.
Dec 14 '07 #2
acoder
16,027 Expert Mod 8TB
What Dasty said, and...
I would like to have it be able to fire an onmouseout without defining it explicitly within the HTML tags.
...why not? Unless you mean inline, in which case you can use linkElem.onmouseout = ... or linkElement.addEventListener("mouseout",...)/linkElement.attachEvent("onmuseout",...).
Dec 14 '07 #3
Okay, that fixed the issue, but now, I'm having another issue - I intended to have it end when the user mouses off of it (notice how I commented out the object.onmouseover and used if(true) instead.) but it continues to be true even after I mouseoff.

EDIT: I did change if(true) to if(object.onmouseover) on line 22.

This would be solved if I did what acoder suggested, but I'm thrown by his response, if someone could explain in further detail about what he meant?
Possibly use an actual example?
Dec 14 '07 #4
acoder
16,027 Expert Mod 8TB
This would be solved if I did what acoder suggested, but I'm thrown by his response, if someone could explain in further detail about what he meant?
Possibly use an actual example?
What I suggested is similar to using an inline onmouseout without declaring it inline.

For example,
Expand|Select|Wrap|Line Numbers
  1. object.onmouseout = someFunc;
where someFunc() is a function.
Dec 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Shelly | last post by:
I set a session variable on error in the login page and then call the login page again. I test on that session variable but it shows as not set. I checked with an echo immediately after setting the...
9
by: E Sullivan | last post by:
I am having a time out issue when multiple users are accessing the server. This time out does not happen all of the time. My understanding is that the time out value is actually set in two places....
6
by: Mike | last post by:
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects....
7
by: Dave | last post by:
Hi all, I have... using System.Collections; namespace MyApp.Templates { public class MyPage : System.Web.UI.Page { ArrayList MyArray = new ArrayList();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.