How to write a JavaScript that will promt user to input data. - The hub of technology | Dedontech

Latest Updates

How to write a JavaScript that will promt user to input data.


A simple JavaScript code that Prompt user to input their data from a pop-up box.

How to use JavaScript to prompt user to input their data and print it out.

In this tutorial you are going to learn how to use JavaScript to ask user to prompt a pop-up box asking users to input their names. For example, the pop-up box will ask user: “What's is your name”. The user will then, input his or are name on the pop-up box and click on ok to the display the inputted name.

The lines of codes below comprises of “HTML, CSS and JavaScript” that will “prompt user upon loading” on browser to “input in their names”.

Also read: how to build website with WordPress

Advertisement
Copy the code below and paste it on a html editor. Save the files with the the name index.html and run the code on your internet browser to see the output.

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Prompt</title>
</head>
<body>
<p id="demo" style="padding-top:3em; padding-left:4em; color:blue";></p>
<script type="text/javascript">
let name = prompt("What's is your name ?");
document.getElementById("demo").innerHTML = "Welcome: " + name;
</script>
</body>
</html>

To learn JavaScript from scratch to become a professional in the following areas below:

  • Web Development
  • Web design
  • Web programming with JavaScript
To become a good web developer, starting from the basic is very important and as time goes on you becomes a guru in developing. If you are looking for more resource to learn about “prompt and alert” in “JavaScript” you can check on www.w3schools.com
Sponsored Links

No comments