Disappearing Text

A

ahtapot

Hello All,

I'm trying to do something relly simple like taking an input from a
text field, and appending it to the bottom of an unordered list I have.
However as soon as I append, the text disappears. I want it to be a
part of the document and to always show whenever my page is loaded. How
can I do that? I must be missing something really basic. Can anyone
help? My code is below.
Thanks!
aht.

<html><head><title>append list element</title> </head><body>


<form name = "form1">

<input type = "submit" name = "button1" onclick = "add();"/>
<input type = "textfield" name ="entry" />


<ul id = "list1">
<li> blah1
<li> blah2

</ul></form>


<script language = "javascript">


function add() {
var frm = document.forms["form1"];
var x = frm.entry.value;
alert(x);
var z = document.createElement("li");
var text1 = document.createTextNode(x);
z.appendChild(text1);
document.getElementById('list1').appendChild(z);


}


</script></body></html>
 
L

Lee

ahtapot said:
Hello All,

I'm trying to do something relly simple like taking an input from a
text field, and appending it to the bottom of an unordered list I have.
However as soon as I append, the text disappears. I want it to be a
part of the document and to always show whenever my page is loaded. How
can I do that? I must be missing something really basic.

Changes that you make in client-side script are not permanent.
They only change the copy of the page that the client is displaying.


--
 
C

Camet

Just throwing an idea out here. Would it be possible to save the input
into an external file. Then when the page is loading, have the script
look to see if the file exists and if there is something in the file,
add it to the webpage? Any extra additions would need to be written
after the stuff already in the file. I know it is possible to do so in
java. Maybe someone can come up with the same script in javascript
 
C

Camet

Just throwing an idea out here. Would it be possible to save the input
into an external file. Then when the page is loading, have the script
look to see if the file exists and if there is something in the file,
add it to the webpage? Any extra additions would need to be written
after the stuff already in the file. I know it is possible to do so in
java. Maybe someone can come up with the same script in javascript
 
K

Kam-Hung Soh

ahtapot said:
Hello All,

I'm trying to do something relly simple like taking an input from a
text field, and appending it to the bottom of an unordered list I have.
However as soon as I append, the text disappears. I want it to be a
part of the document and to always show whenever my page is loaded. How
can I do that? I must be missing something really basic. Can anyone
help? My code is below.
Thanks!
aht.

<html><head><title>append list element</title> </head><body>


<form name = "form1">

<input type = "submit" name = "button1" onclick = "add();"/>
<input type = "textfield" name ="entry" />


<ul id = "list1">
<li> blah1
<li> blah2

</ul></form>


<script language = "javascript">


function add() {
var frm = document.forms["form1"];
var x = frm.entry.value;
alert(x);
var z = document.createElement("li");
var text1 = document.createTextNode(x);
z.appendChild(text1);
document.getElementById('list1').appendChild(z);


}


</script></body></html>

A hack that seems to work is to add to the form element ...

action="javascript:doNothing()"

and define ...

function doNothing() { return; }

My *guess* is that the browser tries to submit the form but there is no
action defined, so it reloads the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top