Important Notice:

Alert box

Alert box

22 views 2 min read

alert() –

यूजर को महत्वपूर्ण संदेश (important message) दिखाने के लिए alert box का उपयोग किया जाता है जो pop up window में खुलता है।

  • इसमें सिर्फ एक बटन होता है – OK
  • यह कोई वैल्यू वापस नहीं करता है। बस दिखता है और OK दबाने पर गायब हो जाता है।

Common Uses of alert()):-

  1. फॉर्म सबमिट होने पर सूचना देना
    जैसे – “आपका रजिस्ट्रेशन सफलतापूर्वक हो गया।”
  2. कोई गलती (error) बताना
    जैसे – “कृपया अपना ईमेल भरें।”
  3. पेज लोड होने पर स्वागत संदेश दिखाना
    जैसे – “वेबसाइट पर आपका स्वागत है!”
  4. किसी वैल्यू को चेक करना
    जैसे – alert("आपकी उम्र है: " + age);

Example

<!DOCTYPE html>
<html>
<body>

<script>
  alert("Hello! Your profile has been saved.");
</script>

<p>An alert box will appear above.</p>

</body>
</html>

alert()

The alert box is used to show important messages to the user. It opens in a pop-up window.

  • It has only one button – OK
  • It does not return any value. It simply appears and disappears when you press OK.

Common Uses of alert():

  • Notify when a form is submitted
    Example: "Your registration has been successful."
  • Show an error message
    Example: "Please fill in your email."
  • Display a welcome message when the page loads
    Example: "Welcome to the website!"
  • Check a value
    Example: alert("Your age is: " + age);

Example:

<!DOCTYPE html>
<html>
<body>

<script>
  alert("Hello! Your profile has been saved.");
</script>

<p>An alert box will appear above.</p>

</body>
</html>

Related Notes