Q. Write a program in JavaScript to accept a name from a user and display the same name in an alert box.
In this lesson you will learned how to display name when the user click the submit button using JavaScript
JavaScript prompt() function:-
Prompt() is used to display the dialog box from the user input . the prompt() function returns the input value if the user click "OK" button on the prompt dialog box otherwise it returns the null value.
For examples:
code: <script>
var name= prompt("enter your name here");
alert(name);
</script>
output:- If the user click "OK" the name is display in an alert box
JavaScript alert() box :-
The alert()
method displays an alert box with a message and an OK button.
The alert()
method is used when you want information to come through to the user.
<!DOCTYPE html>