473,387 Members | 1,407 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,387 software developers and data experts.

Javascript says "document.getElementById("namedisplay") has no properties

I have this script
Expand|Select|Wrap|Line Numbers
  1. function getname(){
  2. <script type="text/javascript">
  3.     var name = prompt('What is your name?');
  4.     while(name==''){
  5.         name = prompt('We need your name?');
  6.     }
  7.     alert(name);
  8.     document.getElementById('namedisplay').value=name;
  9.  
  10. }
  11. getname();
  12. </script>
  13. <input name="namedisplay" type="text" id="namedisplay" value="" />
  14.  
When i run the script it works fine it asks for my name then alerts it back to me but when it is ment to put it into the display box it gets and error saying
"document.getElementById("namedisplay") has no properties"
i am stumped

Can you please help

Thanks Scott
Nov 15 '07 #1
2 1989
mrhoo
428 256MB
you are assigning a value to an element that has not been introduced yet. Move the script, or assign the value when the document has loaded.

onload=function(){document.getElementById('namedis play').value=name};
Nov 15 '07 #2
You can put the input element before javascript code.

Expand|Select|Wrap|Line Numbers
  1. <input name="namedisplay" type="text" id="namedisplay" value="" />
  2.  
  3. <script type="text/javascript">
  4. function getname(){
  5.     var name = prompt('What is your name?');
  6.     while(name==''){
  7.         name = prompt('We need your name?');
  8.     }
  9.     alert(name);
  10.     document.getElementById('namedisplay').value=name; 
  11. }
  12. getname();
  13. </script>
  14.  
Nov 16 '07 #3

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

Similar topics

10
by: AnnMarie | last post by:
What is the best editor to use for JavaScript?
3
by: Plamen Valtchev | last post by:
This is my problem: From JavaScript I want to find the list of all defined/loaded JavaScript functions/objects/names within the current scope (html page in a browser). the page could contain...
1
by: ido | last post by:
Hi all this is my first post here :) I would like to know something about using javascript programaticaly The thing is i have this web site on which when i press a button i uses a function of...
1
by: msdn | last post by:
I know this is not a JavaScript group. Direct me to the right place if you get offended Question: Does anyone know exactly what does code below mean or do. var AZ = Function.AZ =...
1
by: awebguynow | last post by:
I'm actually trying to analyze the Google Suggest code as dissected by C. Justus, eyalamir, alacrity and others. This could be a follow-up to my unanswered posting: Topic: "Google Suggest,...
1
by: Stu | last post by:
Hi, id like to update a literal using javascript in my aspx code i have a literal with a span tag as follows: <td class="mainTitle" style="height:40;"> <asp:Literal ID="litLink"...
5
by: =?Utf-8?B?QVRT?= | last post by:
PRB JavaScript in ASP with Request.Form Please help, I'm having a problem with JavaScript in ASP, where the ASP page crashes when I try to determine if data was posted from a FORM or through a...
2
by: V Rajagopalan | last post by:
can anyone help me to know the syntax being used in javascript and its functions,Properties. For example, when we write code like "text1" followed by "dot" in VB lt display some properties like that...
2
by: NitinSawant | last post by:
Hello, I'm beginner to actionscript, I've defined following function in script tag of page <script type="text/javascript"> function showMessage(){ alert("javascript says: Hello...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.