I wanted to get text from a textbox to display on the same screen. This is the code i have used but it doesn't seem to work. The text prints to the screen but the textbox disappears and I cant enter anything else.
Any help?
<html>
<script language='JavaScript'>
function getwords()
{
textbox = document.getElementById('words');
if (textbox.value != "")
document.write("You entered: " + textbox.value)
else
alert("No word has been entered!")
}
first create your output div in the body (i.e. <div id="output"> Leave blank here </div>
Then in your function get create a variable that accesses the output div (i.e. var myOutput=document.getElementById('output').
Then instead of using the document.write method, just use myOutput.innerHTML="You entered: " + textbox.value;
in a nutshell:
<html>
<script language='JavaScript'>
function getwords(){
myOutput=document.getElementById('output');
textbox = document.getElementById('words');
if (textbox.value != "")
myOutput.innerHTML="You entered: " + textbox.value;
else
alert("No word has been entered!")
}
Bookmarks