473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

writing information from a prompt

I am trying to get the code to write the users name onto the site.

I think i need to call the functon before the page fully loads can someone tell me how to do this or how to fix my problem thanks..
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <SCRIPT LANGUAGE="JavaScript">
  4. function getName() {
  5. var name = prompt("What is your name?", "")
  6. }
  7. document.write("Hello " + name + " welcome to my site");
  8. </SCRIPT>
  9.  
  10.  
  11. </head>
  12. <body>
  13. <BODY onLoad="getName()">
  14. <SCRIPT LANGUAGE="JavaScript">
  15. document.write("Hello " + name + " welcome to my site");
  16. </SCRIPT>
  17. </body>
  18. </html>
Jan 20 '10 #1
2 1669
Hey bboyson,

Your mistake is using document.write in the header. You don't want to write text to the header because text in the header is not visible.

Rather, try putting the same script in the start of the body.

Then you try to use document.write in a script that is accessing a variable which might not have loaded yet. Therefore, don't make it go onload, but rather before. Or, make it go onload, but don't write it until the variable is found - for example:

Expand|Select|Wrap|Line Numbers
  1. function getName() {
  2. var name = prompt("What is your name?", "")
  3. document.body.innerHTML+="Your name is "+name;
  4. }
  5.  
And delete your other two document.writes.

If you wanted to, rather than writing to document.body, you could write to a layer using document.getElementById.
Jan 20 '10 #2
Thank you so much larztheloser
Jan 20 '10 #3

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

Similar topics

1
by: Kelly | last post by:
I want to search for a letter and replace it but when I add the > to the file name it acts up. When I take it out it works but obviously doesn't alter the file only prints it altered. Can anyone...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
2
by: caro | last post by:
Hi I am trying to write two Select * statements to the same text file using bcp (from a stored procedure). But cannot find a way of appending to a file using bcp. Does anyone know if this...
1
by: Taffy Collins | last post by:
I have an ASP page that contains an A HREF tag. This will load a new page and carry some variables to the new page. What I want is that, whenever a person click the item,the prompt box comes up and...
6
by: Dawn Minnis | last post by:
Hi (running Win xp and developing using Miracle C. Running applications in windows command prompt) I'm new to the group so be gentle with me. I am currently writing a C program to perform...
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
6
by: Shooter4Life8 | last post by:
Hi, I am having trouble figureing out the best way to open a command prompt then write lines to it in VB.NET. Currently I have this code, but it execute's too fast I think because Dim psi As...
6
by: ahin | last post by:
can any one help or give an idea about writing or from where to strat the following program? • Load a list of available courses from a text file into an array (max 4 courses). File format can...
15
by: Kasrav | last post by:
Hey there its me again i got this program but i have to improve on it but i am stuck hopefully you can help here is the code def student(): welcome(); info = ...
5
by: no1zson | last post by:
I have been reading through many of the array questions and cannot find one that addresses my issue. Maybe someone can help me out. Same story, I am learning Java and have just written a CD...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.