Click to See Complete Forum and Search --> : How can I combine 2 scripts?


desayuno
01-22-2003, 04:30 AM
How can I combine 2 different scripts?I'd like to have a Mouse Banner on my page, AND a status bar text. I have both scripts, but to let them work, I have to set from both scripts a little bit inbetween the body tags, and at that point they do not work anymore. Only the one I filled in first in the tag, that one works.

Script #1: Mouse Banner:<HEAD>

<style>.spanstyle {
COLOR: white; FONT-FAMILY: Verdana; FONT-SIZE: 8pt; FONT-WEIGHT: bold; POSITION: absolute; TOP: -50px; VISIBILITY: visible
}
</style>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Peter Gehrig -->
<!-- Web Site: http://www.24fun.ch -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var x, y;
var step = 10;
var flag = 0;

var message = "JavaScript is so cool !! ";
message = message.split("");
var xpos = new Array();
for (i = 0; i <= message.length - 1; i++) {
xpos[i] = -50;
}
var ypos = new Array();
for (i = 0; i <= message.length - 1; i++) {
ypos[i]= -50;
}
function handlerMM(e) {
x = (document.layers) ? e.pageX : document.body.scrollLeft + event.clientX;
y = (document.layers) ? e.pageY : document.body.scrollTop + event.clientY;
flag = 1;
}
function makesnake() {
if (flag == 1 && document.all) {
for (i = message.length - 1; i >= 1; i--) {
xpos[i] = xpos[i - 1] + step;
ypos[i] = ypos[i - 1];
}
xpos[0] = x + step;
ypos[0] = y;
for (i = 0; i < message.length - 1; i++) {
var thisspan = eval("span" + (i) + ".style");
thisspan.posLeft = xpos[i];
thisspan.posTop = ypos[i];
}
}
else if (flag==1 && document.layers) {
for (i = message.length - 1; i >= 1; i--) {
xpos[i] = xpos[i - 1] + step;
ypos[i] = ypos[i - 1];
}
xpos[0] = x + step;
ypos[0] = y;
for (i = 0; i < message.length - 1; i++) {
var thisspan = eval("document.span" + i);
thisspan.left = xpos[i];
thisspan.top = ypos[i];
}
}
var timer = setTimeout("makesnake()", 10);
}
// End -->
</script>
</HEAD>
<body bgcolor="#000080" text="#000000" onload="makesnake()"
style="OVERFLOW-X: hidden; OVERFLOW-Y: scroll; WIDTH: 100%">
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
for (i = 0; i <= message.length-1; i++) {
document.write("<span id='span"+i+"' class='spanstyle'>");
document.write(message[i]);
document.write("</span>");
}
if (document.layers) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// End -->
</script>
</body>

Script #2: Status bar News

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function mklist(n)
{
this.length=n;
for (var c=1 ; c <= n ; c++) {
this[c]=0;
}
return this;
}

function browserdelay()
{
var retval=500;
if (navigator.userAgent.indexOf("Win") != 0) {
retval=150;
}
else if (navigator.userAgent.indexOf("Mac") != 0) {
retval=500;
}
else if (navigator.userAgent.indexOf("X11") != 0) {
retval=750;
}
return retval;
}

function mkcfg(n)
{
this.num=1;
this.seed=0;
this.list=new mklist(n);
this.type=new mklist(n);
this.delay=browserdelay();
this.timer=0;
this.showurl=(5 * 1000);
this.looping=true;
this.msgdisp=(4 * 1000);
this.barwidth=100;
return this;
}

function urlfix(obj)
{
window.clearTimeout(window.config.timer);
window.defaultStatus=obj.href;
window.config.timer=window.setTimeout("sbprint()",window.config.showurl);
return true;
}

function scrollit_r2l()
{
var out=" ";
var c=0;

if (window.config.seed <= window.config.barwidth && window.config.seed > 0) {
for (c=0 ; c < window.config.seed ; c++) {
out+=" ";
}
out+=window.config.list[window.config.num];
window.config.seed--;
window.status=out;
window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);
}
else if (window.config.seed <= 0) {
if (-window.config.seed < window.config.list[window.config.num].length) {
out+=window.config.list[window.config.num].substring(-window.config.seed,window.config.list[window.config.num].length);
window.config.seed--;
window.status=out;
window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);
}
else {
window.status=" ";
window.config.num++;
window.config.timer=window.setTimeout("sbprint()",window.config.msgdisp);
}
}
}

window.config=new mkcfg(7);
window.config.list[1]="You can use this for all types of messages ";
window.config.type[1]=0;
window.config.list[2]="This is great as a news ticker ";
window.config.type[2]=0;
window.config.list[3]="Be sure and visit our other sites within internet.com ";
window.config.type[3]=0;
window.config.list[4]="You could put daily updates here ";
window.config.type[4]=0;
window.config.list[5]="You could also use this for daily specials or announcements ";
window.config.type[5]=0;
window.config.list[6]="It is not hard to change the messages ";
window.config.type[6]=0;
window.config.list[7]="You ought to try this! ";
window.config.type[7]=0;

function sbprint()
{
if (window.config.num <= window.config.list.length) {
if (window.config.type[window.config.num] == 0) {
window.status=window.config.list[window.config.num];
window.config.num++;
window.clearTimeout(window.config.timer);
window.config.timer=window.setTimeout('sbprint()',window.config.msgdisp);
}
else if (window.config.type[window.config.num] == 1) {
window.config.seed=window.config.barwidth;
scrollit_r2l();
}
}
else if (window.config.looping) {
window.config.num=1;
window.clearTimeout(window.config.timer);
window.config.timer=window.setTimeout('sbprint()',window.config.delay);
}
}
// End -->

</script>
<BODY onload="window.config.timer=window.setTimeout('sbprint()',window.config.delay);">


I really do not know what to do, I tried almost every possible combination. Can somebody help me???[COLOR=deeppink]

gil davis
01-22-2003, 06:05 AM
Your problem lies in the fact that you are confusing the script part with the html part. Your post is two separate independent pages. You can only have one BODY and one HEAD in a page. The key is to combine these sections from each page into a new page, then combine the stuff in the BODY tag to get the scripts to start. You can combine the onload statements by separating them with a semicolon. Thus:

<HTML>
<HEAD>
<style>
.spanstyle {COLOR: white; FONT-FAMILY: Verdana; FONT-SIZE: 8pt; FONT-WEIGHT: bold; POSITION: absolute; TOP: -50px; VISIBILITY: visible}
</style>
<SCRIPT LANGUAGE="JavaScript">
var x, y;
var step = 10;
var flag = 0;
var message = "JavaScript is so cool !! ";
message = message.split("");
var xpos = new Array();
for (i = 0; i <= message.length - 1; i++) {
xpos[i] = -50;}
var ypos = new Array();
for (i = 0; i <= message.length - 1; i++) {
ypos[i]= -50;}
function handlerMM(e) {
x = (document.layers) ? e.pageX : document.body.scrollLeft + event.clientX;
y = (document.layers) ? e.pageY : document.body.scrollTop + event.clientY;
flag = 1;
}
function makesnake() {
if (flag == 1 && document.all) {
for (i = message.length - 1; i >= 1; i--)
{xpos[i] = xpos[i - 1] + step;
ypos[i] = ypos[i - 1];}
xpos[0] = x + step;
ypos[0] = y;
for (i = 0; i < message.length - 1; i++)
{var thisspan = eval("span" + (i) + ".style");
thisspan.posLeft = xpos[i];
thisspan.posTop = ypos[i];}
}
else if (flag==1 && document.layers) {
for (i = message.length - 1; i >= 1; i--)
{xpos[i] = xpos[i - 1] + step;
ypos[i] = ypos[i - 1];}
xpos[0] = x + step;
ypos[0] = y;
for (i = 0; i < message.length - 1; i++)
{var thisspan = eval("document.span" + i);
thisspan.left = xpos[i];
thisspan.top = ypos[i];}
}
var timer = setTimeout("makesnake()", 10);
}
function mklist(n) {
this.length=n;
for (var c=1 ; c <= n ; c++)
{this[c]=0;}
return this;
}
function browserdelay() {
var retval=500;
if (navigator.userAgent.indexOf("Win") != 0)
{retval=150;}
else
if (navigator.userAgent.indexOf("Mac") != 0)
{retval=500;}
else
if (navigator.userAgent.indexOf("X11") != 0)
{retval=750;}
return retval;
}
function mkcfg(n) {
this.num=1;
this.seed=0;
this.list=new mklist(n);
this.type=new mklist(n);
this.delay=browserdelay();
this.timer=0;
this.showurl=(5 * 1000);
this.looping=true;
this.msgdisp=(4 * 1000);
this.barwidth=100;
return this;
}
function urlfix(obj) {
window.clearTimeout(window.config.timer);
window.defaultStatus=obj.href;
window.config.timer=window.setTimeout("sbprint()",window.config.showurl);
return true;
}
function scrollit_r2l() {
var out=" ";
var c=0;
if (window.config.seed <= window.config.barwidth && window.config.seed > 0)
{for (c=0 ; c < window.config.seed ; c++)
{out+=" ";}
out+=window.config.list[window.config.num];
window.config.seed--;
window.status=out;
window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);}
else if (window.config.seed <= 0)
{if (-window.config.seed < window.config.list[window.config.num].length)
{out+=window.config.list[window.config.num].substring(-window.config.seed,window.config.list[window.config.num].length);
window.config.seed--;
window.status=out;
window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);}
else
{window.status=" ";
window.config.num++;
window.config.timer=window.setTimeout("sbprint()",window.config.msgdisp);}
}
}
window.config=new mkcfg(7);
window.config.list[1]="You can use this for all types of messages ";
window.config.type[1]=0;
window.config.list[2]="This is great as a news ticker ";
window.config.type[2]=0;
window.config.list[3]="Be sure and visit our other sites within internet.com ";
window.config.type[3]=0;
window.config.list[4]="You could put daily updates here ";
window.config.type[4]=0;
window.config.list[5]="You could also use this for daily specials or announcements ";
window.config.type[5]=0;
window.config.list[6]="It is not hard to change the messages ";
window.config.type[6]=0;
window.config.list[7]="You ought to try this! ";
window.config.type[7]=0;
function sbprint() {
if (window.config.num <= window.config.list.length)
{if (window.config.type[window.config.num] == 0)
{window.status=window.config.list[window.config.num];
window.config.num++;
window.clearTimeout(window.config.timer);
window.config.timer=window.setTimeout('sbprint()',window.config.msgdisp);}
else
if (window.config.type[window.config.num] == 1)
{window.config.seed=window.config.barwidth;
scrollit_r2l();}
}
else
if (window.config.looping)
{window.config.num=1;
window.clearTimeout(window.config.timer);
window.config.timer=window.setTimeout('sbprint()',window.config.delay);}
}
</script>
</HEAD>
<body bgcolor="#000080" text="#000000" style="OVERFLOW-X: hidden; OVERFLOW-Y: scroll; WIDTH: 100%" onload="makesnake();window.config.timer=window.setTimeout('sbprint()',window.config.delay);">
<SCRIPT LANGUAGE="JavaScript">
for (i = 0; i <= message.length-1; i++)
{document.write("<span id='span"+i+"' class='spanstyle'>");
document.write(message[i]);
document.write("</span>");}
if (document.layers)
{document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;
</script>
</body>

I hope I didn't lose any of the pieces... ;)

desayuno
01-22-2003, 07:17 AM
Thnx a lot, it really works now!!!!!!!!!!

Greetzzz, me