Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Result 2 Display on Same Page

Status
Not open for further replies.

hiyatran

Technical User
Aug 7, 2010
21
CA
When I hit the submit button, the result are display on a new page. how do I force it to stay on the same page, here's my code.

Code:
<HTML>
<HEAD>
<TITLE>Test Input</TITLE>

<script type="text/javascript">
function addtext() {
   var newtext = document.myform.inputbox.value;
   document.writeln(newtext);
}
</script>

</HEAD>

<BODY>

<FORM NAME="myform">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Check" onClick="addtext()">
</FORM>


</BODY>
</HTML>

any comments or suggestions would be greatly appreciated.

 
[0] There is no submit button there literally.
[1] People should really learn document.writeln() practically at the end of a course rather at the first lesson like w3school is doing which is doing more harm than good in misleading those who want to learn javascript.
[2][tt]
<HTML>
<HEAD>
<TITLE>Test Input</TITLE>

<script type="text/javascript">
function addtext() {
var newtext = document.myform.inputbox.value;
[red]//[/red]document.writeln(newtext);
[blue]document.getElementById("divid").innerHTML=newtext;[/blue]
}
</script>

</HEAD>

<BODY>

<FORM NAME="myform">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Check" onClick="addtext()">
</FORM>
[blue]<div id="divid"></div>[/blue]

</BODY>
</HTML>
[/tt]
 
What tsuji is getting at, is that you aren't really getting a new page as much as you are overwriting the existing one with the document.write() function.

You can use any element such as a span or paragraph to output the text back onto the page as per tsuji's example, it doesn't necessarily have to be a Div, but the basics are there.

And I agree people should really learn what document.write is doing before trying to use it.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top