473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript Problem with document.write( )

1 New Member
Hi I am sunny and a started working on JavaScript recently.
I am stuck up in one script.

The Script goes on like this

[HTML]<HTML>
<HEAD>
<Script Language = "JavaScript ">
function call()
{
var str = prompt("Welcome Your name is", "")
document.write( str)
}
</Script>
</HEAD>
<Body bg color=gray>
<Form name="test">
<Input type="Button" name="b1" value="submit" onClick="call() ">
</Form>
</Body>
</HTML>
[/HTML]
My Question is
Why does the background color goes off when the "document.write " cmd executes.


Please guide me thru.
Nov 21 '07 #1
2 1249
andho
34 New Member
document.write will write to the object from within it is called, for example if it was inside a div it will write to that div erasin everythin inside the div.

so whats happening here is your calling document.write from within the head. I guess it is erasing everything in the document and writing your string to the empty document.
Nov 21 '07 #2
gits
5,390 Recognized Expert Moderator Expert
yes ... thats the point ... you may use innerHtml or proper dom-node-handling for that purpose ... you should never use document.write when a page is loaded already ....

kind regards

ps: changed thread-title to better describe the problem ...
Nov 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2372
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple...
4
1279
by: brainofj | last post by:
Hi, Here is my problem : Here is my first HTML file including a js : <script language="JavaScript" src="http://www.toto.com/monjs.js"></script> In my "monjs.js" :
14
5437
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I...
136
9249
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
9
4896
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ...
13
8283
by: John Smith | last post by:
I am using IE 6.0 from http://www.javaworld.com/javaworld/jw-07-1996/jw-07-javascript-p2.html I gather that "If you need to test a number of command lines, you can reduce the keystrokes by typing javascript: (remember the colon) in the Location box. Navigator displays a "JavaScript typein" frame at the bottom of the window. Type the...
4
2318
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
24
6301
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
23
2597
Frinavale
by: Frinavale | last post by:
JavaScript is a very strange place for me... So, I decided that, before I attempt to create an Object, I should first learn about Objects. I had actually created one before with the help of a tutorial. The tutorial was complicated because showed me how to create a JavaScript Object that is a representation my .NET Object and how to get the two...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.