Views: 0
Input value from the user using prompt html-js.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Input with Prompt</title>
</head>
<body>
<button onclick="getUserInput()">Enter Your Name</button>
<p id="userInputDisplay">Your name will appear here.</p>
<script>
function getUserInput() {
// Prompt the user for input
var userInput = prompt("Please enter your name:");
if (userInput !== null && userInput.trim() !== "") {
// Display the input value in the paragraph element
document.getElementById("userInputDisplay").textContent = "Hello, " + userInput + "!";
} else {
document.getElementById("userInputDisplay").textContent = "You didn't enter a name.";
}
}
</script>
</body>
</html>