Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16306

Re: Quotes are trouble

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Quotes are trouble
Date 2012-10-02 03:21 +0000
Organization A noiseless patient Spider
Message-ID <k4dmj7$3bb$1@dont-email.me> (permalink)
References <c94def8d-8e83-4b79-a971-f6be4acb5f84@r7g2000yqa.googlegroups.com>

Show all headers | View raw


On Mon, 01 Oct 2012 14:36:29 -0700, justaguy wrote:

> What I want to do is, to seed and then replace an image every 500ms.
> 
> HTML code:
> <div id="main"></div>
> 
> js code:
> 	function popMain(img) {
> 			document.getElementById('main').innerHTML = "<img 
src="+img+">";
> 		}
> 
> 	function imgSlides() {
> 		imgs = [];
> 		imgs =
> ['kn1.png','kn2.png','kn3.png','kn4.png','kn5.png','kn6.png'];
> 		for (var i=0; i<6; i++) {
> 			// alert(imgs[i]);
> 			setTimeout(popMain(imgs[i]),500);
> 		}
> 	}
> 
> 
> err msg:
> missing quotes around argument?
> 
> How do we fix the quotes?  Thanks.

Timestamp: 02/10/12 03:00:08
Error: Error: useless setTimeout call (missing quotes around argument?)
Source File: http://www.sined.co.uk/tmp/popmain.htm
Line: 19

This tells me that the error is in the "setTimeout" call, so check the 
syntax of that function.

Looking at the syntax of that call, and googling for that function, the 
function name in the setTimeout call should be in quotes, or the params 
should be passed differently:

setTimeout( "window.document.popMain(imgs[i])", 500 );
setTimeout( popMain, 500, imgs[i] );

However I was having problems with those, and there seems to be a lot of 
contradictory opinion on various websites - how unusual.

So I tried to do looped images with a different approach at:

http://www.sined.co.uk/tmp/popmain.htm

Which seems to be working in my ubuntu/firefox, doesn't use innerHTML, 
uses dom node and element property manipulation.

Rgds

Denis McMahon

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 14:36 -0700
  Re: Quotes are trouble Andrew Poulos <ap_prog@hotmail.com> - 2012-10-02 09:24 +1000
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 17:01 -0700
  Re: Quotes are trouble Stefan Weiss <krewecherl@gmail.com> - 2012-10-02 02:21 +0200
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 17:38 -0700
      Re: Quotes are trouble Stefan Weiss <krewecherl@gmail.com> - 2012-10-02 06:56 +0200
        Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-03 21:33 -0700
          Re: Quotes are trouble "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-04 07:58 +0000
  Re: Quotes are trouble Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-02 03:21 +0000
  Re: Quotes are trouble Norman Peelman <npeelmandog@cfl.rr.com> - 2012-10-02 01:57 -0400
  Re: Quotes are trouble Matt McDonald <matt@fortybelow.ca> - 2012-10-02 12:43 -0400
  Re: Quotes are trouble Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-03 19:27 +0100
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-03 21:34 -0700

csiph-web