prompt() – “यूजर से इनपुट लेने वाला” बॉक्स
prompt() बॉक्स का उपयोग यूजर से कुछ टाइप करने (input) के लिए किया जाता है। यह भी pop‑up window में खुलता है।
- इसमें एक टेक्स्ट फील्ड (लिखने की जगह) होती है + OK और Cancel बटन
- यह एक वैल्यू वापस (return) करता है:
- OK दबाने पर →यूजरनेजोटाइपकिया (string / पाठ)
- Cancel दबाने पर → null
- आप चाहें तो दूसरा पैरामीटर लगाकर पहले से लिखी हुई डिफॉल्ट वैल्यू दे सकते हैं।
prompt() के सामान्य उपयोग (Common Uses of prompt()):
- यूजर से नाम पूछना
जैसे – “कृपया अपना नाम लिखें:”
- यूजर से उम्र पूछना
जैसे – “आपकी उम्र क्या है?”
- कोई गणना करने के लिए नंबर लेना
जैसे – “पहला नंबर दीजिए:”
- यूजर से शहर या पता लेना
जैसे – “आप किस शहर में रहते हैं?”
- डिफॉल्ट वैल्यू के साथ उदाहरण
जैसे – prompt("ईमेल दें:", "user@example.com")
Example:-
<!DOCTYPE html>
<html>
<body>
<script>
let name = prompt("Enter Your Name");
document.write("Hello " + name);
</script>
</body>
</html>
prompt() – The "Take User Input" Box
The prompt() box is used to let the user type something (input). It also opens in a pop‑up window.
- It has a text field (place to type) + OK and Cancel buttons
- It returns a value:
- Click OK → whatever the user typed (as a string)
- Click Cancel → returns null
- You can also provide a second parameter to set a default value that already appears in the text field.
Common Uses of prompt():
- Ask the user for their name
Example: "Please enter your name:"
- Ask the user for their age
Example: "What is your age?"
- Take a number for a calculation
Example: "Enter the first number:"
- Ask the user for their city or address
Example: "Which city do you live in?"
- Example with a default value
Example: prompt("Enter email:", "user@example.com")
- Example:-
<!DOCTYPE html>
<html>
<body>
<script>
let name = prompt("Enter Your Name");
document.write("Hello " + name);
</script>
</body>
</html>