Please help a newbie - Javascript basic

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Oct 2006
Posts: 3
Reputation: flub is an unknown quantity at this point 
Solved Threads: 0
flub flub is offline Offline
Newbie Poster

Please help a newbie - Javascript basic

 
0
  #1
Oct 24th, 2006
Hi All,

I wonder if any Javascript experts can help me. I have the following code on my site which create a rotating graphic in the header every time the page loads. This works great.

However what I want to do is to change the way it works slightly so that I do not have to update the code in the future.

I would like to be able to put all the image address into a text file and then for the javascript to read them from there rather than hard codeing into the web page

or

for the javascript to read all the filenames from a directory of another server?

Is this possible and can anyone help me.

Many thank in advance.




JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. #header {
  2. background:#476 url("http://www.blogblog.com/rounders4/bg_hdr_bot.jpg") no-repeat left bottom;
  3. margin:0 0 0;
  4. padding:0 0 8px;
  5. color:#fff;
  6. }
  7.  
  8. Basically my script works by overwriting the 'background' definition at the <body> part of the template. I wrote the following right after the <body> tag:
  9.  
  10. <script type="text/javascript">
  11.  
  12. var banner= new Array()
  13.  
  14. banner[0]="http://static.flickr.com/84/269053449_acad87a793_o.jpg"
  15. banner[1]="http://static.flickr.com/95/269053438_4ef5a3983e_o.jpg"
  16. banner[2]="http://static.flickr.com/96/269053404_44a3b0eda8_o.jpg"
  17. banner[3]="http://static.flickr.com/108/269053262_608edbdda4_o.jpg"
  18. banner[4]="http://static.flickr.com/98/269053232_6f7c6f994a_o.jpg"
  19. var random=Math.round(4*Math.random());
  20.  
  21. document.write("<style>");
  22. document.write("#header {");
  23. document.write(' background:url("' + banner[random] + '") no-repeat left TOP;');
  24. document.write(" }");
  25. document.write("</style>");
  26.  
  27. </script>
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Please help a newbie - Javascript basic

 
0
  #2
Oct 24th, 2006
HI,

Yes this very Much possible you can use the XML file for store the URLs,
I this in one of my project

here is the solution:

For Example:http://www.katarey.com/forHelp/xml_javascript.html

make a XML file Name

img.xml
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <images>
  3. <img>http://static.flickr.com/84/269053449_acad87a793_o.jpg</img>
  4. <img>http://static.flickr.com/95/269053438_4ef5a3983e_o.jpg</img>
  5. <img>http://static.flickr.com/96/269053404_44a3b0eda8_o.jpg</img>
  6. <img>http://static.flickr.com/108/269053262_608edbdda4_o.jpg</img>
  7. <img>http://static.flickr.com/98/269053232_6f7c6f994a_o.jpg</img>
  8. </images>

then a html/php/asp what ever, i am using xml_javascript.html

xml_javascript.html

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. //http://www.katarey.com
  3. var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
  4. xmlDoc.async="false"
  5. xmlDoc.load("img.xml")
  6. var banner= new Array()
  7.  
  8. nodes=xmlDoc.documentElement.childNodes
  9. banner[0]= nodes.item(0).text
  10. banner[1]= nodes.item(1).text
  11. banner[2]= nodes.item(2).text
  12. banner[3]= nodes.item(3).text
  13. banner[4]= nodes.item(4).text
  14.  
  15. var random=Math.round(4*Math.random());
  16.  
  17. document.write("<style>");
  18. document.write("#header {");
  19. document.write(' background:url("' + banner[random] + '") no-repeat left TOP; width:740px; height:185px;');
  20. document.write(" }");
  21. document.write("</style>");
  22.  
  23. //Remove this Linke after testing
  24. alert(banner[random]);
  25. //*******************************
  26.  
  27. </script>
  28. <body>
  29. <div id="header"> </div>
  30. </body>



Rahul
http://www.katarey.com
Last edited by katarey; Oct 24th, 2006 at 8:01 pm. Reason: for adding the Example
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Please help a newbie - Javascript basic

 
0
  #3
Oct 25th, 2006
That'll only work in Internet Explorer surely? Do Netscape have an XMLDOM object equivalent? I know you can use a XMLHTTP transaction in Windows AND Netscape... but that's possibly overkill.

http://www.jibbering.com/2002/4/httprequest.html
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: BudBrocken is an unknown quantity at this point 
Solved Threads: 0
BudBrocken BudBrocken is offline Offline
Newbie Poster

Re: Please help a newbie - Javascript basic

 
0
  #4
Oct 25th, 2006
Try this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var xmlDoc;
  2. if (window.ActiveXObject)
  3. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  4. else if (document.implementation && document.implementation.createDocument)
  5. xmlDoc= document.implementation.createDocument("","doc",null);
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: flub is an unknown quantity at this point 
Solved Threads: 0
flub flub is offline Offline
Newbie Poster

Re: Please help a newbie - Javascript basic

 
0
  #5
Oct 25th, 2006
Thanks everyone, I will give it a try.

Many many thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC