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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document.write in same page

Status
Not open for further replies.

kondakindi

IS-IT--Management
Apr 18, 2005
31
US
Hi,
I have this html page for validation i have written a Java Script.For diplaying error if any i use window.document.write(" error ");
But it goes to new page is it possible that it goes to the same page just displaying the error on the top or bottom
Thanks
 
Hi kondakindi,

You can't use document.write() for that.
It overwrites the current document.

Replace that command with:
Code:
alert(" error ");

Example:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title></title>
<script>
function ckError(){
	if((1 + 2) != 4) {
		  alert(" error ");
		  }
}
</script>  
</head>
<body>
<input type="button" onclick="ckError()" value="Click Me">

</body>
</html>


Hope it's helpful.

Good Place to "Learn More">>
 
Alternatively, you can include an empty span in your page, and insert the error message into that when you need to:
Code:
<span id="errmsg" style="color:red;font-weight:bold;"></span>

document.getElementById("errmsg").innerText = "You have made an error";

This technique is also handy for displaying debugging messages without a lot of annoying alert boxes.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top