473,387 Members | 1,606 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 Prompt will not appear...

I just starte learning to code. I had a section of HTML, and tried to insert some JavaScript into it. It goes like this:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. alert("Hello there");
  3. alert("I am the Matrix");
  4. var name  = prompt("Enter your name");
  5. alert("Hello" + name + ".");
  6. </script>
Whenever I run it, the prompt does not work. This is what appears:
Hello there.
I am the Matrix.
Helloundefined.

Other notes:
I am using notepad on Windows 8 to type the code.
Whenever I open the page, there is a pop up that asks me if I want to allow blocked content. I have to click this to allow the pop ups to run.
The file is saved as an HTML file, and around that script I have HTML.

If you can please help. Thank you
Jul 18 '14 #1
2 1389
Dormilich
8,658 Expert Mod 8TB
Whenever I open the page, there is a pop up that asks me if I want to allow blocked content. I have to click this to allow the pop ups to run.
that would be the source of the problem. try it with Firefox, Chrome or Safari.

however, in today’s applications there is hardly a need of using prompt() and alert().

when you request data from a user, you would normally have an input field where (s)he can type in the value and then a button to start the processing action (when a click on it was encountered).

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>my page</title>
  5.   </head>
  6.   <body>
  7.     <p>Hello there, I’m the Matrix</p>
  8.     <label for="user-name">Enter your name</label>
  9.     <input type="text" id="user-name">
  10.     <!-- just skipping the real magic and using a simple button instead -->
  11.     <button type="click" id="read-name">that’s me</button>
  12.     <p id="greeting"></p>
  13.     <script type="text/javascript">
  14. // now for some JavaScript magic
  15. document.getElementById('read-name').addEventListener('click', function (evt) {
  16.   // get the name out of the box
  17.   var username = document.getElementById('user-name').value;
  18.   // put the name into the greeting area
  19.   document.getElementById('greeting').textContent = username;
  20. });
  21.     </script>
  22.   </body>
  23. </html>
  24.  
two more advices though

- get a decent code editor with code highlighting, e.g. Notepad++

- regularly check the browser’s error console (should pop up when you hit F12 on most browsers)
Jul 18 '14 #2
Ok thank you for your help
Jul 18 '14 #3

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

Similar topics

3
by: Tommo | last post by:
Hello All, I am a still learning so be easy on me. I am trying to get some code to work that is using JS and Perl/CGI, I am using AS Perl and an Apache Server on XP as the webserver. Can anyone...
3
by: vijay21 | last post by:
hi all, Can we restrict the number of characters that the user can input in a javascript prompt? my browser hangs whenever i try to input more than 2048 characters in it. Thanks for any help
3
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt for the 'rename' function, and a javascript alert...
3
by: Marc | last post by:
Anyone know how to add a drop down menu to a button that will appear when you right click the mouse?
5
by: hcross | last post by:
This project is a web based html and Javascript site. I am working on mac at the moment. This script works except for attempting to open new window once complete. As you can see, i am new to...
1
by: somtabu | last post by:
Hello, in asp.net(VB), i want to display JavaScript alert message after the insert statement is completed. If the insert is failure then the alert message will not come.... Please help
1
by: Aslesha | last post by:
Hi, I am developing a website supporting Arabic language. The direction of all input types I used is right to left. ( using dir attribute ) but the problem is with javascript prompt. I need to...
1
omerbutt
by: omerbutt | last post by:
I first want a pop up that will appear on a third party external website when someone goes to that URL, capture data in pop up form, save that to my database which can be exported as text or csv on...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.