Author Topic: variable inside innerhtml  (Read 4352 times)

0 Members and 1 Guest are viewing this topic.

Offline Xone

  • C= 64
  • **
  • Posts: 79
  • Karma: 10
    • View Profile
variable inside innerhtml
« on: October 18, 2008 »
Hey all,
I'm having some difficulty getting a variable to display on a webpage.
I have strings working, but not values  ???


Inside the JAVA -
Code: [Select]
var MyVariable = 1
document.getElementById("IDhere").innerHTML="The variable is "+MyVariable+" ";
Inside the HTML -
Code: [Select]
<div id="IDhere"> </div>

The firebug debugger in firefox 3 is reporting the error as 'getElementById is Null'.
What am I missing ?

« Last Edit: October 18, 2008 by Xone »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17378
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: variable inside innerhtml
« Reply #1 on: October 18, 2008 »
A semi-colon?

var MyVariable = 1 ;
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Xone

  • C= 64
  • **
  • Posts: 79
  • Karma: 10
    • View Profile
Re: variable inside innerhtml
« Reply #2 on: October 18, 2008 »
missed that in the example above  :)  But no, they all have semi-colons in the main code SW.
This is why I'm confused. I'm sure I've covered everything, and i've been trying to find the problem
for a few days now.

Maybe the innerhtml isn't the fault, maybe there's something wrong with the getElementById part.
« Last Edit: October 18, 2008 by Xone »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17378
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: variable inside innerhtml
« Reply #3 on: October 18, 2008 »
I might be barking up the wrong tree here but I thought that innerhtml was used to alter the text or the html in a page..

By it's nature surely it uses strings?

Code: [Select]
<script type="text/javascript">
function changenumber(){
document.getElementById('IDhere').innerHTML = '2';
}
</script>
<div id='IDhere'>1</div>
<input type='button' onclick='changenumber()' value='CHANGE NUMBER'/>

??
I don't really understand what you're trying to do here sorry.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Xone

  • C= 64
  • **
  • Posts: 79
  • Karma: 10
    • View Profile
Re: variable inside innerhtml
« Reply #4 on: October 18, 2008 »
The webpage (which is a few years old now) used to relay variable data (per second) from the javascript to webpage
using document.all, but since document.all is no longer valid, I have to updated the webpage to use the
getElementById command instead.
The aim is to get the values to display on the webpage in the Firefox 3 browser.

I'm using it for both text and values. As far as I know, values should be possible.
I can't send it as a string shockwave, it has to be a changeable variable because of the frequency it's being updated.


Update:
Problem has finally been solved   :||
« Last Edit: October 20, 2008 by Xone »