473,508 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scrolling text

I am a newbie with Javascript. I have this simple script for scrolling
text
<HTML>
<HEAD>
<TITLE>Scrolling Message Script</TITLE>
<SCRIPT language="JavaScript"><!--
var msg = 'My scrolling text.. '
function scrollMsg(){
document.scrollDemo.textScroll.value = msg
msg = msg.substring(1,msg.length) + msg.substring(0,1)
setTimeout("scrollMsg()", 200)

}
//--></SCRIPT>
</HEAD>

<BODY bgcolor="white" onLoad="scrollMsg()">
<P>
<FORM name="scrollDemo">
<FONT face="Courier New,Courier" size=3><B>

<INPUT type="text" name="textScroll" size=30 value="Loading" ">
</B></FONT>
</FORM>
</BODY>
</HTML>

How must I change the script so that the text stops scrolling when I
put a mouse cursor over the text?
And I would like to have a link to the scrolling text with <atag
e.g.
<a href="/TextDetail/">'My scrolling text.. </a>
Is it possible?

How much difficult would that be ?
Thank you for help
L.

Nov 15 '06 #1
5 4228
PythonistL wrote:
I am a newbie with Javascript. I have this simple script for scrolling
text
<HTML>
<HEAD>
<TITLE>Scrolling Message Script</TITLE>
<SCRIPT language="JavaScript"><!--
var msg = 'My scrolling text.. '
function scrollMsg(){
document.scrollDemo.textScroll.value = msg
msg = msg.substring(1,msg.length) + msg.substring(0,1)
setTimeout("scrollMsg()", 200)

}
//--></SCRIPT>
</HEAD>

<BODY bgcolor="white" onLoad="scrollMsg()">
<P>
<FORM name="scrollDemo">
<FONT face="Courier New,Courier" size=3><B>

<INPUT type="text" name="textScroll" size=30 value="Loading" ">
</B></FONT>
</FORM>
</BODY>
</HTML>

How must I change the script so that the text stops scrolling when I
put a mouse cursor over the text?
Don't use the language attribute on the script tag. It is deprecated.

Don't bother with the comment trick to hide the script from Netscape 1
or which every browser it was a long time ago.

It is probably a good idea to explicitly type the semi-colons at the
end of the JavaScript lines.

It might be better to use lower case tag and attribute names in case
you want to switch to XML/XHTML

Consider using a document type and validating your HTML
http://validator.w3.org/

I'm assuming your script example works. To stop the scrolling you can
keep and use a reference to the timeout. Note setTimeout can take a
function reference instead of a string if you want and it is more
efficient.

<script type="text/javascript">

var msg = 'My scrolling text..';
var myTimeout;
function scrollMsg() {
document.scrollDemo.textScroll.value = msg;
msg = msg.substring(1,msg.length) + msg.substring(0,1);
myTimeout = setTimeout(scrollMsg, 200);
}
</script>

<input type="text" onmouseover="if (myTimeout) {
clearTimeout(myTimeout; }">

And I would like to have a link to the scrolling text with <atag
e.g.
<a href="/TextDetail/">'My scrolling text.. </a>
Is it possible?
Maybe you really want

<a href="#textScroll">'My scrolling text.. </a>

I don't know about using the pound anchor with a name attribute. I use
the pound anchor with an element id this is because the name attributes
are not required to be unique but the id attributes are unique.

Peter

Nov 15 '06 #2
Hello Peter,
Thank you for your reply.
I changed the script as you suggested
<HTML>
<HEAD>
<TITLE>Scrolling Message Script</TITLE>

<script type="text/javascript">
var msg = 'My scrolling text.....';
var myTimeout;
function scrollMsg() {
document.scrollDemo.textScroll.value = msg;
msg = msg.substring(1,msg.length) + msg.substring(0,1);
myTimeout = setTimeout(scrollMsg, 200);
}
</script>
</HEAD>

<BODY bgcolor="white" onLoad="scrollMsg()">

<FORM name="scrollDemo">
<INPUT type="text" onmouseover="if (myTimeout) { clearTimeout(
myTimeout; }" name="textScroll" size=30 value="Loading" >
</FORM>
</BODY>
</HTML>

but the scrolling text still does NOT stop when I put a mouse cursor
over the text.
Where did I make a mistake in the script?
Thank you for your reply.
L.

Nov 16 '06 #3
PythonistL wrote:
Hello Peter,
Thank you for your reply.
I changed the script as you suggested

<HTML>
<HEAD>
<TITLE>Scrolling Message Script</TITLE>

<script type="text/javascript">
var msg = 'My scrolling text.....';
var myTimeout;
function scrollMsg() {
document.scrollDemo.textScroll.value = msg;
msg = msg.substring(1,msg.length) + msg.substring(0,1);
myTimeout = setTimeout(scrollMsg, 200);
}
</script>
</HEAD>

<BODY bgcolor="white" onLoad="scrollMsg()">

<FORM name="scrollDemo">
<INPUT type="text" onmouseover="if (myTimeout) { clearTimeout(
myTimeout; }" name="textScroll" size=30 value="Loading" >
</FORM>
</BODY>
</HTML>

but the scrolling text still does NOT stop when I put a mouse cursor
over the text.
Where did I make a mistake in the script?
I made the mistake. I missed a right paren on the call to clearTimeout.
I just ran the page in Firefox and Firebug filled me in on the problem.
Try this. It worked for me

<INPUT type="text" onmouseover="if (myTimeout) {
clearTimeout(myTimeout); }"

All those capitalized tag names have got to go. Ok they don't _have_ to
but they look old fashioned.

You should write all attributes in double quotes

size="30"

Check out firebug
https://addons.mozilla.org/firefox/1843/

Peter

Nov 16 '06 #4
Do you really want to use an input element? For this scrolling text?

Below is an example without using an input element. It uses the
non-standard innerHTML property that all the main browsers have. You
could do this using the standard dom methods too but I just wanted to
show a quick example.

<HTML>
<HEAD>
<TITLE>Scrolling Message Script</TITLE>

<script type="text/javascript">
var msg = 'My scrolling text.....';
var myTimeout;
function scrollMsg() {
document.getElementById('textScroll').innerHTML = msg;
msg = msg.substring(1,msg.length) + msg.substring(0,1);
myTimeout = setTimeout(scrollMsg, 200);
}

</script>
</HEAD>

<BODY bgcolor="white" onLoad="scrollMsg()">

<p type="text" onmouseover="if (myTimeout) { clearTimeout(
myTimeout); }" id="textScroll">
</p>

</BODY>
</HTML>

Nov 16 '06 #5

Peter ,
Thanks a lot for your help. Now it works! I little changed it like
this:

<p type="text" onmouseover="if (myTimeout) { clearTimeout( myTimeout);
}" onmouseout="myTimeout = setTimeout(scrollMsg, 200); "
id="textScroll">

Now when I move the mouse cursor from a text the scrolling starts
again.
So, now it is ALMOST what I needed.Only I miss only one thing.
Do you have any idea how I can add a URL link to the scrolling text so
that a user can click on a text and a new page is open ?Or where can I
learn more about that?

Thank you for your reply
L.

Nov 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16664
by: Midas NDT Sales | last post by:
I have been looking at a simple example of a scrolling text box (the one in the SAM book) as below: <script language="JavaScript"> var pos=100; function Scroll() { if...
44
919
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
1
3584
by: Wesman | last post by:
Threads, textboxes and scrolling Thanks in advance for any information on this matter. I have run into a small richtextbox, scrolling and tread issue. Which has me totally confused. Instead of...
5
21676
by: Will Gillen | last post by:
I need to have a "scrolling" text label or textbox at the bottom of my window to show the URL of where a song is being played from. I want the text to scroll on a single line from left to right in...
2
2944
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a...
4
7739
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
1
2464
by: Thorsten Kleinweber | last post by:
Hello, I did some first steps in programming a site for a friend and have some questions concerning web design. The site is http://www.stevanez-juls.de: 1. On my tft display (with low...
3
11717
by: Chamnap | last post by:
Hello everybody, I have one problem. I want to do something after the user finished scrolling. The scroll event fires whenever the user is scrolling. I don't want this actually. Does anyone has...
0
7231
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
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
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
5643
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,...
1
5059
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...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.