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


Groups > comp.lang.javascript > #16298 > unrolled thread

Quotes are trouble

Started byjustaguy <lichunshen84@gmail.com>
First post2012-10-01 14:36 -0700
Last post2012-10-03 21:34 -0700
Articles 13 — 8 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#16298 — Quotes are trouble

Fromjustaguy <lichunshen84@gmail.com>
Date2012-10-01 14:36 -0700
SubjectQuotes are trouble
Message-ID<c94def8d-8e83-4b79-a971-f6be4acb5f84@r7g2000yqa.googlegroups.com>
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.

[toc] | [next] | [standalone]


#16302

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-10-02 09:24 +1000
Message-ID<CYydnejLr4-9u_fNnZ2dnUVZ_s-dnZ2d@westnet.com.au>
In reply to#16298
On 2/10/2012 7:36 AM, justaguy wrote:
> "<img src="+img+">";

You could trt

"<img src='"+img+"'>";

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#16303

Fromjustaguy <lichunshen84@gmail.com>
Date2012-10-01 17:01 -0700
Message-ID<ea54c13e-84dc-4d95-b261-9e25b1527138@l32g2000yqb.googlegroups.com>
In reply to#16302
On Oct 1, 7:24 pm, Andrew Poulos <ap_p...@hotmail.com> wrote:
> On 2/10/2012 7:36 AM, justaguy wrote:
>
> > "<img src="+img+">";
>
> You could trt
>
> "<img src='"+img+"'>";
>
> Andrew Poulos

Good thought, but still same error.

[toc] | [prev] | [next] | [standalone]


#16304

FromStefan Weiss <krewecherl@gmail.com>
Date2012-10-02 02:21 +0200
Message-ID<k4dc2g$3g8$1@news.albasani.net>
In reply to#16298
On 2012-10-01 23:36, justaguy wrote:
> 			setTimeout(popMain(imgs[i]),500);

popMain(imgs[i]) is executed immediately.

https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout

> err msg:
> missing quotes around argument?

What kind of an error message is that?
You should at least get a line number.


- stefan

[toc] | [prev] | [next] | [standalone]


#16305

Fromjustaguy <lichunshen84@gmail.com>
Date2012-10-01 17:38 -0700
Message-ID<7561a517-388d-4e1d-b2cb-a10bb9da6dc8@o7g2000yqb.googlegroups.com>
In reply to#16304
On Oct 1, 8:21 pm, Stefan Weiss <krewech...@gmail.com> wrote:
> On 2012-10-01 23:36, justaguy wrote:
>
> >                    setTimeout(popMain(imgs[i]),500);
>
> popMain(imgs[i]) is executed immediately.
>
> https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout
>
> > err msg:
> > missing quotes around argument?
>
> What kind of an error message is that?
> You should at least get a line number.
>
> - stefan

error line:
setTimeout(popMain(imgs[i]),1000);

But I set up an alert right under popMain function for the parameter
of img
alert(img); // and just in case img is special, I renamed it to imag
to no avail neither
and it passes its value correctly.

[toc] | [prev] | [next] | [standalone]


#16307

FromStefan Weiss <krewecherl@gmail.com>
Date2012-10-02 06:56 +0200
Message-ID<k4ds67$nod$1@news.albasani.net>
In reply to#16305
On 2012-10-02 02:38, justaguy wrote:
> On Oct 1, 8:21 pm, Stefan Weiss <krewech...@gmail.com> wrote:
>> > err msg:
>> > missing quotes around argument?
>>
>> What kind of an error message is that?
>> You should at least get a line number.

> error line:
> setTimeout(popMain(imgs[i]),1000);

Next time, please include the full error message, so we know what to
focus on. And incidentally, it should tell you, too, where the problem
is (i.e., the setTimeout call).

> But I set up an alert right under popMain function for the parameter
> of img
> alert(img); // and just in case img is special, I renamed it to imag
> to no avail neither
> and it passes its value correctly.

That's because popMain is not the problem, like the error message and I
already told you. The problem the way you call setTimeout. I also
included a link to a page which explains exactly how it works. You
should have read it :(
It states right on the top of the page that the first argument must be a
function reference or a string.

What you're doing instead is this:

  setTimeout(popMain(imgs[i]),1000)

This calls popMain(imgs[i]) right away, without any delay. The popMain
function does its thing and returns nothing (undefined).
Now the execution is at this point:

  setTimeout(undefined, 1000)

And that's where you get the error: "useless setTimeout call (missing
quotes around argument?)", because undefined is not a valid argument for
setTimeout.

Now if you add quotes around the argument -

  setTimeout("popMain(imgs[i])", 1000)

- then the setTimeout call succeeds, but a second later you'll get a
ReferenceError because i is not defined. What you should do instead is

1) read the docs if somebody points you to the relevant page

2) use: setTimeout("popMain(imgs[" + i + "])", 1000)


- stefan


PS: the next surprise will come when your script, now "working", will
only display kn6.png after the timeout. Why?

[toc] | [prev] | [next] | [standalone]


#16380

Fromjustaguy <lichunshen84@gmail.com>
Date2012-10-03 21:33 -0700
Message-ID<d60b3d05-c1bc-4c29-aee4-e4f340ea9d61@c2g2000yqe.googlegroups.com>
In reply to#16307
On Oct 2, 12:56 am, Stefan Weiss <krewech...@gmail.com> wrote:
> On 2012-10-02 02:38, justaguy wrote:
>
> > On Oct 1, 8:21 pm, Stefan Weiss <krewech...@gmail.com> wrote:
> >> > err msg:
> >> > missing quotes around argument?
>
> >> What kind of an error message is that?
> >> You should at least get a line number.
> > error line:
> > setTimeout(popMain(imgs[i]),1000);
>
> Next time, please include the full error message, so we know what to
> focus on. And incidentally, it should tell you, too, where the problem
> is (i.e., the setTimeout call).
>
> > But I set up an alert right under popMain function for the parameter
> > of img
> > alert(img); // and just in case img is special, I renamed it to imag
> > to no avail neither
> > and it passes its value correctly.
>
> That's because popMain is not the problem, like the error message and I
> already told you. The problem the way you call setTimeout. I also
> included a link to a page which explains exactly how it works. You
> should have read it :(
> It states right on the top of the page that the first argument must be a
> function reference or a string.
>
> What you're doing instead is this:
>
>   setTimeout(popMain(imgs[i]),1000)
>
> This calls popMain(imgs[i]) right away, without any delay. The popMain
> function does its thing and returns nothing (undefined).
> Now the execution is at this point:
>
>   setTimeout(undefined, 1000)
>
> And that's where you get the error: "useless setTimeout call (missing
> quotes around argument?)", because undefined is not a valid argument for
> setTimeout.
>
> Now if you add quotes around the argument -
>
>   setTimeout("popMain(imgs[i])", 1000)
>
> - then the setTimeout call succeeds, but a second later you'll get a
> ReferenceError because i is not defined. What you should do instead is
>
> 1) read the docs if somebody points you to the relevant page
>
> 2) use: setTimeout("popMain(imgs[" + i + "])", 1000)
>
> - stefan
>
> PS: the next surprise will come when your script, now "working", will
> only display kn6.png after the timeout. Why?

The previous ones have been replaced.
I attempted with changing image source at each "interval",
document.images.show.src = imag;
to no avail neither.
Wouldn't that suggest the interval of 1000ms (1second) not really
working?  I don't get it.

Thanks.

[toc] | [prev] | [next] | [standalone]


#16385

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-04 07:58 +0000
Message-ID<XnsA0E26574DE19Beejj99@194.109.133.133>
In reply to#16380
justaguy wrote on 04 okt 2012 in comp.lang.javascript:

> The previous ones have been replaced.
> I attempted with changing image source at each "interval",

in Javascript there is a large difference between interval and timeout.

> document.images.show.src = imag;
> to no avail neither.

Double negative! Start debugging.

> Wouldn't that suggest the interval of 1000ms (1second) not really
> working?  I don't get it.

In some instances certainly not, 
if the size is to large to be loaded on a low speed connection. 

Do you realy know the minimum connection bandwith/speed of your web-users?

You should preload the images or perhaps use <img onload='...'

> document.images.show.src = imag;

This depends on just one <img> having the name "show",
and what the content of imag is.

Did you do any debugging yet?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#16306

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-10-02 03:21 +0000
Message-ID<k4dmj7$3bb$1@dont-email.me>
In reply to#16298
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

[toc] | [prev] | [next] | [standalone]


#16309

FromNorman Peelman <npeelmandog@cfl.rr.com>
Date2012-10-02 01:57 -0400
Message-ID<k4dvo4$8au$1@dont-email.me>
In reply to#16298
On 10/01/2012 05:36 PM, 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.
>

setTimeout("popMain(imgs[i])",500)


-- 
Norman
Registered Linux user #461062
AMD64X2 6400+ Ubuntu 10.04 64bit

[toc] | [prev] | [next] | [standalone]


#16314

FromMatt McDonald <matt@fortybelow.ca>
Date2012-10-02 12:43 -0400
Message-ID<k4f5l4$8cu$1@dont-email.me>
In reply to#16298
On 01/10/12 17:36, justaguy wrote:

> What I want to do is, to seed and then replace an image every 500ms.

Instead of replacing an image, consider modifying its `src` property.

> HTML code:
> <div id="main"></div>

To implement such a strategy, author the image directly into the HTML
source. Then access the image via the DOM API. Consequently only one
element is ever created; and if properly authored, the image will be
usable to clients with JavaScript disabled.

>setTimeout(popMain(imgs[i]),500);

You are immediately invoking the function entitled `popMain'. Since it
does not return a function, when the time to invoke a callback arrives,
an error may be thrown. Instead, consider passing the parameter to a
function that will generate a callback as follows:

function createImageCallback(
         img
)
{
         return function () {
                 var el = img;
                 // code here
         };
}

function createImageTimer(
         img
)
{
         [global object].setTimeout(
                 createImageCallback(img),
                 500
         );
}

[toc] | [prev] | [next] | [standalone]


#16363

FromDr J R Stockton <reply1240@merlyn.demon.co.uk.invalid>
Date2012-10-03 19:27 +0100
Message-ID<vVADdTCKOIbQFwmd@invalid.uk.co.demon.merlyn.invalid>
In reply to#16298
In comp.lang.javascript message <c94def8d-8e83-4b79-a971-f6be4acb5f84@r7
g2000yqa.googlegroups.com>, Mon, 1 Oct 2012 14:36:29, justaguy
<lichunshen84@gmail.com> posted:

>What I want to do is, to seed and then replace an image every 500ms.

Then you should find a page that does something like that, and copy the
relevant part of its code.  Or copy the lot, to make sure that you have
what is needed, such as CSS and include files, and then remove what you
do not need.

Once you have that working, you can then start to make modifications,
always preserving a known-good version.

Such code can, for example, be found at
         <http://www.merlyn.demon.co.uk/js-date2.htm#SC>
         <http://www.merlyn.demon.co.uk/js-shufl.htm#GRI>.

And if you then post here the minimum code that you have found to be
necessary for your basic task, you can post it here in order to be told
how it could be done better.

-- 
 (c) John Stockton, nr London UK               Reply address via Home Page.
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

[toc] | [prev] | [next] | [standalone]


#16381

Fromjustaguy <lichunshen84@gmail.com>
Date2012-10-03 21:34 -0700
Message-ID<c441a491-4ca8-4ff5-abff-3a9d84cc499d@a17g2000yqg.googlegroups.com>
In reply to#16363
On Oct 3, 2:27 pm, Dr J R Stockton
<reply1...@merlyn.demon.co.uk.invalid> wrote:
> In comp.lang.javascript message <c94def8d-8e83-4b79-a971-f6be4acb5f84@r7
> g2000yqa.googlegroups.com>, Mon, 1 Oct 2012 14:36:29, justaguy
> <lichunshe...@gmail.com> posted:
>
> >What I want to do is, to seed and then replace an image every 500ms.
>
> Then you should find a page that does something like that, and copy the
> relevant part of its code.  Or copy the lot, to make sure that you have
> what is needed, such as CSS and include files, and then remove what you
> do not need.
>
> Once you have that working, you can then start to make modifications,
> always preserving a known-good version.
>
> Such code can, for example, be found at
>          <http://www.merlyn.demon.co.uk/js-date2.htm#SC>
>          <http://www.merlyn.demon.co.uk/js-shufl.htm#GRI>.
>
> And if you then post here the minimum code that you have found to be
> necessary for your basic task, you can post it here in order to be told
> how it could be done better.
>
> --
>  (c) John Stockton, nr London UK               Reply address via Home Page.
>    news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
>    <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
>    <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

I did that already.  Thanks tho.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web