![]() | ![]() |
|
Welcome to the HEXUS.community discussion forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! |
| |||||||
| Software and web development Databases, graphics, programming, scripting and web development. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| VTECmeous Join Date: Aug 2003
Posts: 1,861
Thanks: 41
Thanked 47 Times in 46 Posts
| After yet more trawling for decent code and a healthly dislike for easy-way-out prebuilt code packs I've run into a javascript issue I've so far failed to leaver myself out of. Can you see where I've gone wrong? Aim: A timed banner which consists of multiple hidden divs'. Code: var c=0;timedBanner is called from the body onload and currently set to timedBanner(2) mainBanner is a div containing 2 hidden divs called serviceBanner1 and serviceBanner2 Problem: The initial banner loads correctly. On the second pass I get an objectexpected error on the line starting banners[1] Why? No doubt it's a small problem but I can't see it at present. Help please! 1 : Q9450 | 4Gb PC8500 DMX | ASUS P5E-WS Pro | HD2900XT | 2 x 750Gb (RAID1) | Adaptec ASR-2230SLP SCSI | DVDRW | Corsair 650W TX | CM RC-590 | 2x VP171s-2 | HP Ultrium 960 LTO3 | XP SP3 Pro 2 : X2 4200+ | 2Gb PC3200 | ASUS A8N-SLI Premium | 6600GT | SonicFury | 8x 250Gb (2x RAID10) | 3Ware 9650SE-8LPML | DVDRW | Seasonic 700W | CM Stacker 830 | 2x VP171s-2 | XP SP3 Pro 3 : Sm 3100+ | 1Gb PC3200 | ASUS K8N-E Deluxe | 9800 Pro | 4 x 250Gb Maxline III (RAID10) | DVDRW | CDRW | Tagan 530W Easycon | CM ATC-201B-BXT Black Widow | W7 RC W : Dell Precision 690 | Intel X5355 | 4Gb FBDIMM | Quadro FX3450 | 2x 146Gb 15k SAS (RAID1) | DVDRW | DVD | 2x 2007FP | XP SP3 Pro
Last edited by Vimeous; 02-11-2009 at 01:21 PM.. |
| | |
| | #2 (permalink) |
| Three As fanboy... Join Date: Jan 2009 Location: Manchester
Posts: 1,600
Thanks: 60
Thanked 119 Times in 117 Posts
| Re: Javascript: Timed Banner Not Working Code: function timedBanner(divs)
{
switchBanner(c);
c=c+1;
if (c > divs -1) {
c = 0;
}
t=setTimeout("timedBanner()",1000);
}
Code: t=setTimeout("timedBanner(divs)",1000);
// // TODO: Add witty signature here // |
| | |
| Received thanks from: | Vimeous (03-11-2009) |
| | #3 (permalink) |
| VTECmeous Join Date: Aug 2003
Posts: 1,861
Thanks: 41
Thanked 47 Times in 46 Posts
| Re: Javascript: Timed Banner Not Working Originally Posted by scaryjim Thanks Jim. I'd taken it out thinking it'd stop the loop running ad-infinitum but I see that would not be the case (and I was getting a different error).
I now get an error that with "divs" being undefined. How is it best to define "divs" in this circumstance? 1 : Q9450 | 4Gb PC8500 DMX | ASUS P5E-WS Pro | HD2900XT | 2 x 750Gb (RAID1) | Adaptec ASR-2230SLP SCSI | DVDRW | Corsair 650W TX | CM RC-590 | 2x VP171s-2 | HP Ultrium 960 LTO3 | XP SP3 Pro 2 : X2 4200+ | 2Gb PC3200 | ASUS A8N-SLI Premium | 6600GT | SonicFury | 8x 250Gb (2x RAID10) | 3Ware 9650SE-8LPML | DVDRW | Seasonic 700W | CM Stacker 830 | 2x VP171s-2 | XP SP3 Pro 3 : Sm 3100+ | 1Gb PC3200 | ASUS K8N-E Deluxe | 9800 Pro | 4 x 250Gb Maxline III (RAID10) | DVDRW | CDRW | Tagan 530W Easycon | CM ATC-201B-BXT Black Widow | W7 RC W : Dell Precision 690 | Intel X5355 | 4Gb FBDIMM | Quadro FX3450 | 2x 146Gb 15k SAS (RAID1) | DVDRW | DVD | 2x 2007FP | XP SP3 Pro
|
| | |
| | #4 (permalink) |
| Three As fanboy... Join Date: Jan 2009 Location: Manchester
Posts: 1,600
Thanks: 60
Thanked 119 Times in 117 Posts
| Re: Javascript: Timed Banner Not Working Oops! sorry, I forgot that setTimeout takes a string for the command to run. You'll need to do Code: t=setTimeout("timedBanner(" + divs + ")",1000);
)!EDIT: it doesn't make me immune to writing questionable / deprecated code, either! There's two versions of setTimeout, the one you're using which runs some text input as a code snippet, and a newer version that takes a function object (I won't go into the complexity of *everything* being an object in javascript) that you can then add parameters to. The generalised form is: window.setTimeout(func, delay, [param1, param2, ...]);, so your code snippet should be Code: t=setTimeout(timedBanner, 1000, divs); // // TODO: Add witty signature here // Last edited by scaryjim; 03-11-2009 at 12:53 PM.. |
| | |
| Received thanks from: | Vimeous (03-11-2009) |
| | #5 (permalink) |
| VTECmeous Join Date: Aug 2003
Posts: 1,861
Thanks: 41
Thanked 47 Times in 46 Posts
| Re: Javascript: Timed Banner Not Working Originally Posted by scaryjim A definite improvement! ...... but now I'm back to the previous error:
In IE7/8 I get an objectexpected error on the line starting banners[1]. In Firefox 3.5 I get document.getElementById("serviceBanner1") is null. Both errors imply I've got the function switchBanner wrong. The HTML code for divs themselves is: <div id="mainBanner">I wonder if it's related to the divs being hidden. That said both browsers display the first banner and only trigger an error when the running the subsequent code. Confused! ![]() n.b. Sorry if you cringed at the lack of class for the images - that'll appear if it starts working 1 : Q9450 | 4Gb PC8500 DMX | ASUS P5E-WS Pro | HD2900XT | 2 x 750Gb (RAID1) | Adaptec ASR-2230SLP SCSI | DVDRW | Corsair 650W TX | CM RC-590 | 2x VP171s-2 | HP Ultrium 960 LTO3 | XP SP3 Pro 2 : X2 4200+ | 2Gb PC3200 | ASUS A8N-SLI Premium | 6600GT | SonicFury | 8x 250Gb (2x RAID10) | 3Ware 9650SE-8LPML | DVDRW | Seasonic 700W | CM Stacker 830 | 2x VP171s-2 | XP SP3 Pro 3 : Sm 3100+ | 1Gb PC3200 | ASUS K8N-E Deluxe | 9800 Pro | 4 x 250Gb Maxline III (RAID10) | DVDRW | CDRW | Tagan 530W Easycon | CM ATC-201B-BXT Black Widow | W7 RC W : Dell Precision 690 | Intel X5355 | 4Gb FBDIMM | Quadro FX3450 | 2x 146Gb 15k SAS (RAID1) | DVDRW | DVD | 2x 2007FP | XP SP3 Pro
Last edited by Vimeous; 03-11-2009 at 04:11 PM.. |
| | |
| | #6 (permalink) |
| Three As fanboy... Join Date: Jan 2009 Location: Manchester
Posts: 1,600
Thanks: 60
Thanked 119 Times in 117 Posts
| Re: Javascript: Timed Banner Not Working Originally Posted by Vimeous Hmm, you have indeed got the code for switchBanner wrong! The first time the code is called, it rewrites over the whole of the content of mainBanner with the content of serviceBanner1. This [b]writes over[/i] the content of both serviceBanner1 and servicebanner2, so they no longer exist in the document tree. Any future attempt to reference either of them is doomed to failure, because they don't exist anymore!
Sorry, I didn't even look at your switchBanner code before because I'd spotted a problem in your earlier code (and frankly I wasn't treating this like a formal code review ).if you want to do it this way I *think* setting up the banners array outside of the function might work. A better way to change whether you can see a DIV programatically is to set its .style.display property: Code: document.getElementById("serviceBanner1").style.display = "block";
document.getElementById("serviceBanner2").style.display = "none";
Originally Posted by Vimeous I'm not concerned by the lack of a class so much as putting the attribute in when you're not using it
but as you say, that'll come with time... // // TODO: Add witty signature here // |
| | |
| Received thanks from: | Vimeous (05-11-2009) |
| | #7 (permalink) |
| VTECmeous Join Date: Aug 2003
Posts: 1,861
Thanks: 41
Thanked 47 Times in 46 Posts
| Re: Javascript: Timed Banner Not Working Originally Posted by scaryjim
BIG thanks for pointing out I was overwriting the code. I'm definitely not a pro-web-app-dev! That said I reckon I can get an alternate solution working to those you suggest. Instead of replacing the content of mainBanner I just need to add an empty named div as the content of mainBanner is hidden. Then I can replace the content of that as often as I like ![]() Of course I've just tried this and I seem to have too many entires ...... but it is has shown divs 1 and 2 this time lol (actually it works in firefox but ie is declaring issues with undefined stuff hmm.....) 1 : Q9450 | 4Gb PC8500 DMX | ASUS P5E-WS Pro | HD2900XT | 2 x 750Gb (RAID1) | Adaptec ASR-2230SLP SCSI | DVDRW | Corsair 650W TX | CM RC-590 | 2x VP171s-2 | HP Ultrium 960 LTO3 | XP SP3 Pro 2 : X2 4200+ | 2Gb PC3200 | ASUS A8N-SLI Premium | 6600GT | SonicFury | 8x 250Gb (2x RAID10) | 3Ware 9650SE-8LPML | DVDRW | Seasonic 700W | CM Stacker 830 | 2x VP171s-2 | XP SP3 Pro 3 : Sm 3100+ | 1Gb PC3200 | ASUS K8N-E Deluxe | 9800 Pro | 4 x 250Gb Maxline III (RAID10) | DVDRW | CDRW | Tagan 530W Easycon | CM ATC-201B-BXT Black Widow | W7 RC W : Dell Precision 690 | Intel X5355 | 4Gb FBDIMM | Quadro FX3450 | 2x 146Gb 15k SAS (RAID1) | DVDRW | DVD | 2x 2007FP | XP SP3 Pro
Last edited by Vimeous; 05-11-2009 at 04:18 PM.. |
| | |
| | #8 (permalink) |
| VTECmeous Join Date: Aug 2003
Posts: 1,861
Thanks: 41
Thanked 47 Times in 46 Posts
| Originally Posted by scaryjim scary I've double checked the code again and it turns out only the longer original code you suggested (top one) will work with both Firefox 3.5 and IE 7. I'll check IE 8 shortly.
Many thanks for your help. While I know I've 'cheated' by using another empty div it also keeps the code simpler for myself and those who follow to maintain. Now I'm off to canabalise the fade in/out I discovered recently 1 : Q9450 | 4Gb PC8500 DMX | ASUS P5E-WS Pro | HD2900XT | 2 x 750Gb (RAID1) | Adaptec ASR-2230SLP SCSI | DVDRW | Corsair 650W TX | CM RC-590 | 2x VP171s-2 | HP Ultrium 960 LTO3 | XP SP3 Pro 2 : X2 4200+ | 2Gb PC3200 | ASUS A8N-SLI Premium | 6600GT | SonicFury | 8x 250Gb (2x RAID10) | 3Ware 9650SE-8LPML | DVDRW | Seasonic 700W | CM Stacker 830 | 2x VP171s-2 | XP SP3 Pro 3 : Sm 3100+ | 1Gb PC3200 | ASUS K8N-E Deluxe | 9800 Pro | 4 x 250Gb Maxline III (RAID10) | DVDRW | CDRW | Tagan 530W Easycon | CM ATC-201B-BXT Black Widow | W7 RC W : Dell Precision 690 | Intel X5355 | 4Gb FBDIMM | Quadro FX3450 | 2x 146Gb 15k SAS (RAID1) | DVDRW | DVD | 2x 2007FP | XP SP3 Pro
|
| | |
| | #9 (permalink) |
| Three As fanboy... Join Date: Jan 2009 Location: Manchester
Posts: 1,600
Thanks: 60
Thanked 119 Times in 117 Posts
| Re: Fixed ..... interesting ..... Originally Posted by Vimeous Hmm, quite possible. IE prior to 8 didn't bother about following the standards too closely! if there's a version that works with everything stick with that one
![]() You should find the second version works OK in IE8 I think - in my experience so far they've done a much better job of making it adhere to the standard... my biggest problem is that some of the sites I design for a living are targetted at the NHS and some NHS trusts still haven't upgraded from IE6 because their in-house developed web apps are coded for specific IE6 hacks, so not only do I have to code for several different browsers, I also have to be prepared for 3 different versions of IE! // // TODO: Add witty signature here // |
| | |
| | #10 (permalink) |
| Large Member Join Date: Apr 2004
Posts: 3,368
Thanks: 25
Thanked 27 Times in 22 Posts
| Re: Javascript: Timed Banner Not Working Or you could just use jquery and not spend 4 days completeing the simplest of scripts To err is human. To really foul things up ... you need a computer. |
| | |
![]() |
| Breadcrumb | ||||||
| ||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adsense Banner - How much money? | oshta | General discussion | 12 | 23-10-2009 11:12 AM |
| Very odd issue: Some website's images won't load | TheVoice | Help - technical & advisory | 10 | 29-03-2007 04:18 PM |
| Pipex problems, DOS attacks or ? ? | Carnagerover | Networking and Broadband | 14 | 25-01-2007 01:14 PM |
| CS:S Lag problems | NoExcuse | Help - technical & advisory | 28 | 06-02-2006 04:31 PM |
| Simple Banner Script Javascript or PHP Advice | ikonia | Software and web development | 2 | 12-07-2005 07:29 PM |