vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Javascript push function (https://vborg.vbsupport.ru/showthread.php?t=214361)

powerful_rogue 05-23-2009 08:33 AM

Javascript push function
 
Hi,

Im playing with the following code, but for some reason cant seem to get the "push" function to operate.

This is my code below

PHP Code:

<title>Image Array</title>

<
SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">

adImages = new Array("images/banner/dods.gif","images/banner/dovermemorial1.gif","images/banner/doverlocals.gif","images/banner/DoverLifeboatBanner.gif")
adURL = new Array("dods.com""dover.gov.uk","doverlocals.co.uk","lifeboat.org.uk")

thisAd 0
imgCt 
adImages.length

  
function rotate() {
  if (
document.images) {
  
thisAd++
  if (
thisAd == imgCt) {
  
thisAd 0
  
}
  
document.adBanner.src=adImages[thisAd]
  
setTimeout("rotate()" imgCt 1000)
  }
  
  }
  
function 
newLocation() {
 
document.location.href "http://www." adURL[thisAd]
 }
  
adImages.push("images/banner/freecycle.jpg")
  
adURL.push("freecycle.org")

  </
script>
  
</
head>

<
BODY BGCOLOUR=BLUE onLoad="rotate()">
<
center>
<
A HREF="javascript:newLocation()">
<
IMG SRC="images/banner/dods.gif" WIDTH=468 HEIGHT=60 NAME="adBanner" BORDER="0"></A>

</
center>
</
body>
</
html

I want to be able to add a banner onto the end of adImages and a webaddress onto the end of adURL

The current arrays work fine, however I cant seem to get the new ones in the push command to be added!

Any help greatly appreciated!

UKBusinessLive 05-25-2009 06:55 PM

Hiya PR

I noticed you have a few minor errors in your code this is what the top half should look like

PHP Code:

adImages = new Array("images/banner/dods.gif","images/banner/dovermemorial1.gif","images/banner/doverlocals.gif","images/banner/DoverLifeboatBanner.gif"");
adURLS = new Array("
http://www.dods.com","http://www.dover.gov.uk","http://www.lifeboat.org.uk" );
thisAd 0;
imgCt adImages.length;

function 
rotate() {
if (
document.images) {
thisAd++;
if (
thisAd == imgCt) {
thisAd 0;
}
document.adbanner.src=adImages[thisAd];
document.getElementById('ad').href adURLS[thisAd];
setTimeout("rotate()"14 1000);
}


Try not to use too many white spaces with Javascript, and don't leave the semi colons out neither ;)
Code:

imgCt = adImages.length;
Plus the url's will need to be the full urls complete with http://www etc....

Try changing your code to the above and see if you can get it to work, i would imagine your creating some form of banner slideshow??

Hope this helps, let us know the result


All times are GMT. The time now is 04:04 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01650 seconds
  • Memory Usage 1,733KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete