CodeLab
Tutorials For Everyone
Run
<!DOCTYPE html> <html> <head> <title>JavaScript prompt() Function Tutorial - TutsInsider</title> <style> .main{ padding: 10px; } .main-heading{ background: #333333; color: #ffffff; padding: 20px; } .main-paragraph{ margin-top: -20px; padding: 20px; box-shadow: inset 0 0 3px 0 #2a73cc; } .main-button{ padding: 5px 10px; margin: 5px; border: none; border-radius: 5px; background: #333333; color: #ffffff; box-shadow: 0 0 3px 0 #333333; cursor: pointer; } </style> </head> <body> <div class="main"> <h2 class="main-heading">What is JavaScript prompt() Function?</h2> <div class="main-paragraph"> The prompt() function in JavaScript is used to display a prompt dialog box to the user and ask for input. The function returns the user's input as a string. <br /> <strong>First Name: </strong><span id="fname">First Name Here</span> <br /> <strong>Last Name: </strong><span id="lname">Last Name Here</span> <br /> <button class="main-button" onclick="promptFunction()">Click Here</button> </div> </div> <script> function promptFunction() { let f_name = prompt("What is your first name?"); let l_name = prompt("What is your last name?"); document.getElementById("fname").innerHTML = f_name; document.getElementById("lname").innerHTML = l_name; } </script> </body> </html>