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


Groups > comp.lang.javascript > #18143

Re: Why is this not working

Message-ID <14011564.rDXmUOF8TW@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-01-19 18:26 +0100
Subject Re: Why is this not working
Newsgroups comp.lang.javascript
References <kdei12$7eg$1@dont-email.me>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Tony Johansson wrote:

> I'm quite now to javascript
            ^^^
There is no “javascript” [1] and YSCIB.

> and wonder why is not the called function
> changinf the value for element with id=demo
  ^^^^^^^^
Please take more when writing your Usenet articles.
 
> <!DOCTYPE html>
> <html>
> <body>
> 
> <p id="demo">testing</p>
> 
> <script>
> function myFunction(a,b)
> {
>    return a*b;
> }

Learn pretty printing to make source code easily readable

  function myFunction (a, b)
  {
    return a * b;
  }
 
> for (int i = 0; i< 10; i++)
-------^
Syntax error.  “int” is a *future* reserved word; these languages are 
*dynamically* typed.  Perhaps you were looking for

> document.getElementById("demo").innerHTML=myFunction(4,3);

  for (var i = 0; i < 10; ++i)
  {
    document.getElementById("demo").innerHTML = myFunction(4, 3);
  }

Which begs the question: Why do you want to execute this 10 times?
Why do you expect the result of the first iteration to be different
from that of the fifth or the tenth?

Accessing an element before the document has been loaded, like this,
also is not reliably.  Move your code to a function that you call from

  <body … onload="…">
    …
  </body>

________
[1] <http://PointedEars.de/es-matrix>
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

Why is this not working "Tony Johansson" <johansson.andersson@telia.com> - 2013-01-19 17:35 +0100
  Re: Why is this not working Tim Streater <timstreater@greenbee.net> - 2013-01-19 16:52 +0000
    Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-19 18:45 +0100
  Re: Why is this not working Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-01-19 10:17 -0700
  Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-19 18:26 +0100
    Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-19 18:50 +0100
  Re: Why is this not working Richard Yates <richard@yatesguitar.com> - 2013-01-19 11:11 -0800
    Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-19 21:17 +0100
      Re: Why is this not working Richard Yates <richard@yatesguitar.com> - 2013-01-19 14:30 -0800
        Re: Why is this not working Stefan Weiss <krewecherl@gmail.com> - 2013-01-20 02:52 +0100
          Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-20 03:08 +0100
            Re: Why is this not working Stefan Weiss <krewecherl@gmail.com> - 2013-01-20 04:32 +0100
              Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-20 04:46 +0100
  Re: Why is this not working Danny <dann90038@gmail.com> - 2013-01-19 12:42 -0800
    Re: Why is this not working "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-19 22:53 +0100
  Re: Why is this not working Jeff North <jnorthau@yahoo.com.au> - 2013-01-20 15:13 +1100
    Re: Why is this not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-20 06:45 +0100
  Re: Why is this not working Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-20 18:20 +0000

csiph-web