Forum Moderators: open

Message Too Old, No Replies

Inserting value from javascript to table.

How to insert value of variable from javascript to table in HTML

         

kenchix1

6:27 am on Apr 29, 2008 (gmt 0)

10+ Year Member



I'm new to javascript and I got a .js file and modified it so that it gives random number and store it in an array.

Storing the random number inside the array is working properly but I can't put the value inside the a table in a separate HTML file.

Inside the .js file, this is the part that prints the value to the table of the html file .


document.getElementById("nos1").innerHTML = rnos[0]
document.getElementById("nos2").innerHTML = rnos[1]

Inside the html file, I have a table where I wanted the numbers to appear, but it is not working. Aside from that I don't want the numbers to appear inside the <p></p> tags because it put spaces. I only wanted it to appear inside the <td></td> tags. But I don't know how to make it appear inside the table that's why I use the <p> tags and put an ID in it.


<td class='bbox1'><p id="nos1"></p></td>
<td class='bbox1'><p id="nos2"></p></td>
<a href="javascript:GetRandomNow()">Random numbers</a>

This code isn't working.

Is there a way that it would work like a PHP variable where I just have to echo the variable name ?

Any suggestions please ?

Thanks.

daveVk

12:26 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



change <p id="nos1"></p> to <span id="nos1"></span> should resolve formating issue.

put the value inside the a table in a separate HTML file

Assuming the file in question is the currently loaded page (onload event has fired) your code looks Ok. It will not work if executed to early or "file" is within a frame.

The PHP variable works while the page is being generated, in this case the page (file) preexists.

kenchix1

2:54 am on Apr 30, 2008 (gmt 0)

10+ Year Member



Thanks ! :)

Got it, that's why it is not working properly because it is executed earlier.