View Full Version : appending text to a page
nhojuil
10-06-2002, 06:18 PM
Is it possible to append text to the bottom of a page using JavaScript? That is, I want to be able to make a page like this -
Initially, there is only a button. Click the button, and some text, like "Hi" is displayed under the button. Click the button again, and another Hi is added under the first Hi, ad infinitum.
Thanks in advance for any help you can give me.
Nhojuil
Eternity Angel
10-06-2002, 06:59 PM
If you want an endless loop of adding "Hi" below a button, then this would work:
<input type="button" value="Click Me!" onclick="repeat.innerHTML = repeat.innerHTML+'Hi<br>';">
<br>
<span id="repeat"> </span>
nhojuil
10-06-2002, 09:30 PM
Thanks very much. What if I had a table under the button and wanted to add more rows? I can't seem to make that work using the same code.
Eternity Angel
10-06-2002, 09:47 PM
Well, when I can't get .innerHTML to work, I stuff the HTML into variables. THIS works, but is just a cheap supliment, none the less:
<script>
table_rows = '<table border><tr><td>Something</td></tr>';
table_center = '<tr><td>Something</td></tr>';
table_end = '</table>';
function doTable()
{
repeat.innerHTML = table_rows+table_end;
table_rows = table_rows+table_center;
}
</script>
<input type="button" value="Click Me!" onclick="doTable();">
<br>
<span id="repeat">
</span>
nhojuil
10-06-2002, 09:58 PM
Thanks very very much.
Eternity Angel
10-06-2002, 10:02 PM
Then you're welcome very very much ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.