PDA

View Full Version : Automate scroller???



rrnml
08-10-2006, 09:59 PM
1) Script Title: Fading Message Scroller

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex2/fadescroll.htm

3) Describe problem:
I am not having a problem with the scroller. It is working fine. However, I do have a couple of questions. I would like to know if it's possible for any of your scrollers to be automated. I have a file that is populated with sales information by date. What I would like to do is automate that scroller so that it reads the file each day and updates the sales info for that day. Is this possible? I would appreciate any help with this. Thanks.

jscheuer1
08-11-2006, 04:51 AM
Well, if you could make your external file look like this:


var fcontent=new Array();
fcontent[0]="<b>What\'s new?</b><br>New scripts added to the Scroller category!<br><br>The MoreZone has been updated. <a href='../morezone/index.htm'>Click here to visit</a>";
fcontent[1]="Dynamic Drive has been featured on Jars as a top 5% resource, and About.com as a recommended DHTML destination.";
fcontent[2]="Ok, enough with these pointless messages. You get the idea behind this script.</a>";


And be named, say - fcontent.js, then you could remove the above lines from the script (be sure to leave especially these and all the other lines in the scroller script):


begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations
closetag='</div>';


and put this on your page before the scroller script:


<script type="text/javascript" src="fcontent.js"></script>

That would do it. In fact, if you wanted to, and have a server side scripting language and data base available for this project, you could have your server generate the file as "fcontent.asp", or "fcontent.php", etc. and use that name as the src attribute. Both php and asp (and other server side languages) can be used to pull variables from the server's data base to construct a file with the proper syntax for the script.

rrnml
08-11-2006, 03:44 PM
The file as it is now resides on an AS400. Is this still possible or would I have to FTP that file to one of our SQL servers and name it as you suggested?

jscheuer1
08-11-2006, 05:58 PM
Fortunately, javascript source files may be accessed across domains, so you could use:


<script type="text/javascript" src="http://www.somedomain.com/fcontent.js"></script>

The filename's extension can still be .php, .asp, or whatever. Links - source paths to images, etc., if any, within the file should be written either relative to the page that will use them or (preferably) in absolute terms.

rrnml
08-18-2006, 10:18 PM
How would I go about opening the connection to the AS400 to get to that file?

jscheuer1
08-18-2006, 10:28 PM
How would I go about opening the connection to the AS400 to get to that file?

If it is on the internet, just use the file's address as the src attribute.

rrnml
08-18-2006, 10:33 PM
The file is located in a library on the AS400. I would be using the asp page where the scroller script is to extract from the db file. So I'm thinking I would need to open a connection to that AS400 from there. I just don't know if it's possible.

jscheuer1
08-19-2006, 07:40 AM
Hmm, you are moving outside my area of expertise. Ideally the server side/javascript file should be on the server where the db is. Then it can be called by its address from anywhere on the internet. If you have access to both servers, this is the way to go. If you have a way of accessing the db on one server from the other (like if they are linked via an intranet), it could probably be worked out with the server side/javascript file being on the other server but, I have no idea if that could or how that would be done.

rrnml
08-21-2006, 04:05 PM
If I could get that information into an .asp file, what format does that file need to be in, in order to get it to work with the scroller?

jscheuer1
08-22-2006, 01:52 AM
If I could get that information into an .asp file, what format does that file need to be in, in order to get it to work with the scroller?

OK, now we are talking. It needs to be written by the server to appear to the browser as a javascript file. The extension would need to be .asp so that the server will write it. As an example, see this post:

http://www.dynamicdrive.com/forums/showpost.php?p=40466&postcount=1

where I lay out a method for using a .asp file to compile an array of image names from a given folder. Look at that code and see how it intersperses javascript and asp/VBscript. The server will write out its side of the code, the javascript part is literal, the result would be a file that looks something like this:


var counter=0
var galleryarray=new Array()
galleryarray[0]=["some.jpg", "10/24/05"]
galleryarray[1]=["someother.jpg", "05/07/06"]


and so on until all the images in the directory are written to the array. This file would be read by the browser and then the script on the page that this file is linked to would have access to the images from the directory as an array.

You need the server to read your db and have it write out an asp page with an array like this one:


var fcontent=new Array();
fcontent[0]="<b>What\'s new?</b><br>New scripts added to the Scroller category!<br><br>The MoreZone has been updated. <a href='../morezone/index.htm'>Click here to visit</a>";
fcontent[1]="Dynamic Drive has been featured on Jars as a top 5% resource, and About.com as a recommended DHTML destination.";
fcontent[2]="Ok, enough with these pointless messages. You get the idea behind this script.</a>";

Using your data as the red parts.

rrnml
08-22-2006, 11:19 PM
Ok I will try to figure that one out. It is something new for me so I'll work on it. I do have another question I regarding the code for this ticker. Can I pass a parameter to it? Here is an example of what I have running currently. My question is for fcontent[1], fcontent[3], and fcontent[5] can I pass a variable to those?


var fcontent=new Array();
begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations
fcontent[0]="Instant Sales for Monday, August 21, 2006";
fcontent[1]="$251,298";
fcontent[2]="Daily Sales needed to meet goal of $91.5 million";
fcontent[3]="$253,061";
fcontent[4]="Current Average <br>Daily Instant Sales";
fcontent[5]="$236,053";
closetag='</div>';

jscheuer1
08-23-2006, 02:30 AM
Sure, if you already know how many fcontent[x] entries that you want and you only want to populate a few of them, your job is considerably easier.

Think of it this way - just like you can make a server side variable appear on a page in the midst of html code:


<div> Sales today were <%= dbEntry.daySales %>. </div>

You can also make one appear in an externally linked file in the midst of javascript code:


fcontent[1]="<%= dbEntry.daySales %>";

Either way, when the server serves the page, if it has a .asp extension, the value will be substituted and read by the user's browser.

And, don't worry too much about being new to this, I'm an old hand at javascript and HTML but, you probably know more about .asp/VBscript than I do.

rrnml
08-23-2006, 05:18 PM
So where you say dbEntry.daySales, what does dbEntry stand for. The structure of the file is library.file.field ....... So my file is rachelr.slinstnp.sldate ... Would I use <%= slinstnp.sldate %> or am I way off? If that is so, I tried and I just get a blank. It displays the text but when it comes to the amount, it's blank.

rrnml
08-23-2006, 06:06 PM
So I figured out why it wasn't working. It dawned on me that you said .asp file and the file I was working on was a .htm file. Duh! So apparently it's not possible to carry that out using a .htm. Another question I have is, can you pass that parameter from the .asp to the .htm? Just a thought in case the bosses don't want to change the .htm to a .asp

jscheuer1
08-23-2006, 07:09 PM
Well, here is where it gets interesting. Let's say you have a file named fcontent.asp and in it you have this:


fcontent=new Array();
fcontent[0]="Sales Today:";
fcontent[1]="<%= dbEntry.daySales %>";

Then on your .htm page, you could have this (oversimplified) code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="fcontent.asp"></script>
</head>
<body>
<script type="text/javascript">
document.write(fcontent[0]+' '+fcontent[1])
</script>
</body>
</html>

It would then display:

Sales Today: $200,423.00

or whatever the value of dbEntry.daySales is at that moment. I think you can see where this is going, if you populate the array, as I originally suggested, in an external file that accesses the db and link that file to the page before the script code on the page that uses its values, they will be available to it (and therefore to the .htm page itself).

rrnml
08-23-2006, 11:00 PM
Well they're ok with the .asp so this will do. I thank you so much for your help with this. I really do appreciate it.