473,320 Members | 2,104 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,320 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 1378
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.