Artikel Terbaru

Dialog


Introduction to JavaScript Dialogs 
Dialog box एक छोटी दूसरी window होती है जो current window के अंदर ही generate होती है। इन्हें popup boxes भी कहते है। Dialog boxes के द्वारा 3 तरह के काम किये जा सकते है।

  • आप कोई भी alert show कर सकते है। 


  • User से कोई भी task perform करने से पहले confirm कर सकते है। 


  • Input की requirement होने पर यूज़र से input ले सकते है। 



  • JavaScript में dialog boxes उनके काम के according 3 तरह के होते है। इनके बारे में नीचे दिया जा रहा है। 














    Alert Dialog Box 

    Alert box यूज़र को कोई important message show करने के लिए यूज़ किया जाता है। जब आप चाहते है की यूज़र आपके message को जरूर पढे ऐसी situation में आप alert box यूज़ कर सकते है।



    ये box current window से focus हटा देता है और only message शो होता है। साथ ही alert box में एक ok का button भी होता है जिस पर click करने से alert box हट जाता है। 

    JavaScript में alert dialog generate करने के लिए आप alert function call करते है। इस function में आप जो message शो करना चाहते है उसे argument की तरह लिखते है। इसका उदाहरण नीचे दिया गया है। 

    <html>

    <head>

    <title>Alert box demo</title>

    </head>



    <body>



    <script type="text/javascript"> 
    alert("This is an alert box");
    </script>     



    </body>



    </html>


    ऊपर दी गई script निचे दिया गया webpage generate करती है।



    javascript-alert-dialog-example-output


    Confirm Dialog Box 

    Confirm dialog box यूज़र से किसी task के बारे में confirmation लेने के लिए यूज़ किया जाता है। ये एक छोटी सी window होती है जिसमे yes और no buttons होते है। जिसमें yes button यूज़र की सहमती दर्शाता है और no button show करता है की यूज़र proceed करना नहीं चाहता है। 

    JavaScript में confirm dialog box generate करने के लिए आप confirm method को call करते है। इस method में आप एक message argument की तरह pass करते है जो यूज़र से confirmation मांगता है। जैसे की आप यूज़र से पूछते है की आप ये book खरीदना चाहते है?



    इसका उदाहरण नीचे दिया जा रहा है। 

    <html>

    <head>

    <title>Confirm dialog demo</title>

    </head>



    <body>



    <script type="text/javascript">
    if(confirm("Do you want to buy this book?"))
    {
        document.write("User wants to buy the book");
    }
    </script>



    </body>

    </html>
        
    उपर दिये गए उदाहरण में यदि user confirm box में yes select करता है तो if statement में दिया गया message webpage पर print हो जाता है। ये script निचे दिया web page generate करती है।



    javascript-confirm-dialog-example-output

    यदि user OK पर  click करता है तो message show होता है नहीं तो कुछ भी show नहीं होता है।  


    Prompt Dialog Box 

    यदि आप user से कोई input लेना चाहते है तो आप prompt dialog box यूज़ कर सकते है। Prompt dialog box में एक text-box होता है और एक ok button होता है। Text-box में user value input करता है। Prompt box create करने के लिए आप prompt() method को call करते है।



    इस method में 2 parameters pass किये जाते है। पहला parameter वो label होता है जो text-box में क्या value डालनी है ये show करता है। दूसरे parameter में text-box की default value pass की जाती है। इसका उदाहरण नीचे दिया जा रहा है।



    <html>

    <head>

    <title>prompt box demo</title>

    </head>



    <body>

    <script type="text/javascript">
    var age = prompt("Enter your age", 18);
    document.write("Age is :",age);
    </script>

    </body>



    </html>

    ऊपर दी गयी script निचे दिया गया webpage generate करती है। 

    javascript-prompt-dialog-example-output

    User जो value input के रूप में देगा OK पर click करने पर उसे appropriate message के साथ print किया जायेगा। 

    Post a Comment

    0 Comments