/  Technology   /  Prompt Box
Prompt Box

Prompt Box

 

A prompt box is frequently used when you want the user to enter a value before proceeding to the next page. When a question box appears, the user must select “OK” or “Cancel” to proceed after providing an input value. When the user hits “OK,” the box returns the value entered.

The prompt() method displays a dialog box that prompts the user for input.

The prompt() method returns the input value if the user clicks “OK”, otherwise it returns null.

Prompt box provides a textbox/ input text field to the user to collect data at runtime.

JavaScript Code:

<html>
<title>
    Promt Box
</title>

<body>
    <script>
        const name = prompt('What is your name?');
        const course = prompt('Which Course we are learning ?');
        alert(`Hello ${name}, Welcome to our group...!` + `We are
        learning ${course}`);
    </script>
</body>

</html>

Prompt Box

 

When the user clicks Cancel or presses the Esc key, prompt () returns, null.

p2

<script>
    const name = prompt('What is your name?');
    const course = prompt('Which Course we are learning ?');
    alert(`Hello ${name}, Welcome to our group...!` + `We are
    learning ${course}`);
</script>

 

When we add field values, it will display the alert box shown below.

 

Leave a comment