/    Sign up×
Community /Pin to ProfileBookmark

how to join strings

I need use concat function to join strings in this script but I’m doing something wrong because instead all messages from array were scrolling as one is status bar for me they are showing letter by letter. How to use concat here?

[CODE]
<head>
<script language=”JavaScript”>
<!–
Msg = new String(2);
Msg[0] = “message1”;
Msg[1] = “message2”;
Msg[2] = “message3″;
var c=0
var cntr=0;

for (v=0; v<=2; v++)
{
for (i=0; i<120; i++){
Msg[v]=” “+Msg[v];
}
}

function StatusScroll()
{
if (cntr>2)
cntr=0;

if (c < Msg[cntr].length)
{
window.status=Msg[cntr].substring(c,Msg[cntr].length);
c++
}
else
{
c=0;
cntr++;
}
setTimeout(“StatusScroll()”,50);
}

function String(size)
{
this.length = size;
for(var i = 1; i <= size; i++)
{
this[i] = “”;
}
return this;
}
//–>
</script>
</head>
<body onload=StatusScroll();>
[/CODE]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@Tweak4Jan 16.2007 — Could you be a little more specific? Your description doesn't make a whole lot of sense, and the code you posted doesn't do anything, aside from adding spaces to the front of your strings... (Unless you add a call to StatusScroll() to get things rolling, that is).

I'm not entirely sure what you're trying to accomplish here, but I am reasonably certain there is probably a better way to do it. For example, why did you write a function to initialize a string array, instead of using the built-in Array functions in js? Also, why are you declaring an array with a length of 2 and immediately filling the first 3 elements?

Furthermore, are you [I]really [/I]sure this is what you want to do at all? Many browsers no longer let you override the status bar text (and rightly so), so a good number of your potential visitors would never know this script ever existed or what your messages were.
Copy linkTweet thisAlerts:
@AnnaccondauthorJan 16.2007 — If there's a better way to make simple text scrolling in status bar using various string functions than I would be grateful if someone would gave me other solution.
Copy linkTweet thisAlerts:
@toicontienJan 16.2007 — How about this?
<i>
</i>var Messages = {
msgs: [],
interval: null,

add: function(msg) {
this.msgs[msgs.length] = msg;
},

scroll: function() {
this.interval = setInterval(StatusScroll, 50);
},

toString: function() {
return this.msgs.length &gt; 0 ? this.msgs.join(' ') : '';
}
};

Messages.add("message1");
Messages.add("message2");
Messages.add("message3");
Messages.add("message4");
Messages.add("message5");
Messages.add("message6");
Messages.add("message7");
Messages.add("message8");
Messages.add("message9");

var c=0
var cntr=0;

function StatusScroll()
{
var msg = Messages.toString();
if (cntr&gt;2)
cntr=0;

if (c &lt; msg.length)
{
window.status=msg.substring(c,msg.length);
c++
}
else
{
c=0;
cntr++;
}
}

And when you want the messages to scroll, just add this line of code:
Messages.scroll();
Copy linkTweet thisAlerts:
@felgallJan 16.2007 — Of course any updates you apply in the status bar will only appear when your visitors have disabled the security option in their browser that disallows web pages accessing the status bar.
Copy linkTweet thisAlerts:
@AnnaccondauthorJan 17.2007 — How about this?

And when you want the messages to scroll, just add this line of code:
Messages.scroll();[/QUOTE]

Looks good but I think I do something wrong because it don't want work :o Without onload in body it showing error and with onload showing blank page and nothing happend in status. I'm not sure where to add Messages.scroll() - I tried in body onload and in code but surely it's still wrong place. Sorry I know my problem maybe it's stupid but I'm really JS n00b who just starting work with it. Please help ?

Of course any updates you apply in the status bar will only appear when your visitors have disabled the security option in their browser that disallows web pages accessing the status bar.[/QUOTE]
Yes I know but it's school homework so it doesn't depend from me what teachers demand from us :rolleyes:
Copy linkTweet thisAlerts:
@KorJan 17.2007 — ... I always wondered why at school professors s insist always to teach you either deprecated or non ethical methods...:rolleyes:
Copy linkTweet thisAlerts:
@toicontienJan 18.2007 — I got your PM Anna ? I had a silly javascript syntax error. Here is the working code:
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>Status bar test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- begin hiding
var Messages = {
msgDivider: ' | ',
msgs: [],
interval: null,

add: function(msg) {
this.msgs[this.msgs.length] = msg;
},

scroll: function() {
this.interval = setInterval(StatusScroll, 50);
},

toString: function() {
return this.msgs.length > 0 ? this.msgs.join(this.msgDivider) : '';
}
};

Messages.add("message1");
Messages.add("message2");
Messages.add("message3");
Messages.add("message4");
Messages.add("message5");
Messages.add("message6");
Messages.add("message7");
Messages.add("message8");
Messages.add("message9");

var c=0
var cntr=0;

function StatusScroll()
{
var msg = Messages.toString();
if (cntr>2)
cntr=0;

if (c < msg.length)
{
window.status=msg.substring(c,msg.length);
c++
}
else
{
c=0;
cntr++;
}
}
// end hiding -->
</script>
</head>
<body onload="Messages.scroll();">
<p>Scrolling message page</p>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@AnnaccondauthorJan 18.2007 — Thank you very much for help [B]toicontien[/B] ?
Copy linkTweet thisAlerts:
@rush73Jan 18.2007 — The Beedly.com directory of websites. Great solutions for web masters and SEO programers.

Beedly is a quality and large directory of websites. Over 2 millions websites and 290 000 categories.

Add your website to us directory and get:

Get link popularity bonus.

Increase traffic of visitors to your website.

and more.

Beedly directory is new non-commercial project. And we hope you will help us in building large and quality directory with easy and freandly search system.


http://www.beedly.com Directrory of websites

http://beedly.com

Become an editor.

Thank you.

Andrew J. Green
×

Success!

Help @Annaccond spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...