Please navigate to the bottom of the page for Table of Contents

Saturday, June 4, 2011

Differentiate between alert(), prompt() and confirm() methods

Although jQuery is the new craze, traditional javascript knowledge is still required and forms a core part of a web developer interview. One of the common questions is about making sure the interviewee understands the different mechanisms of communicating with the user. The javascript window object uses dialog boxes to interact with the user. The dialog boxes are created with three methods:
• alert()
• prompt()
• confirm()

alert() dialog

The alert() dialog box is used to communicate a message to the user (generally warnings of missed actions). For example, if the email address entered is wrong, you can use the alert() message to warn the user about it. Developers also use alerts() as a quick and dirty way to debug their applications.

// warning
alert("Invalid email address. Please enter again.");
// debugging
alert(currentCounter);



The alert() method creates a new pop-up window (dialog box) which contains the user message and an
OK button. This is a modal window and all execution is stopped until the user clicks the OK button in the pop-up box.


image


prompt() dialog


The prompt() method asks the user for some small input such as a password, completion of a form input, or personal information, such as nickname or title. The prompt dialog box pops up with a simple text box. After the user enters text into the prompt dialog box, its value is returned (or null in case the user hit cancel).


prompt("Please enter your nickname", "nickname");



The prompt method takes in 2 arguments – the prompt message and a default value. The default value is optional and if provided is filled in the text box and is selected by default.


image


confirm() dialog


The confirm dialog box is used to confirm a user’s answer to a question. This method takes only one argument, the question you will ask the user. A question mark will appear in the box with an OK button and a Cancel button. If the user clicks the OK button, true is returned; if he or she clicks the Cancel button, false is returned. This is also a modal dialog  - the user must agree before the action is completed. You often see this in shopping cart applications just before placing the order or on file sharing sites just before you delete a file.  


if (confirm("Are you sure you want to delete your profile photo?") == true) {
alert("Deleting photo...");
}
else {
alert("Glad you decided against deleting the photo!");
}


image

To summarize, the different mechanisms that javascript provides you to interact with the user are alert, prompt and confirm. Hopefully with the explanation, code and screenshots, this is clear to you.

111 comments:

  1. this is easy to understand and useful!

    thank you very much!

    ReplyDelete
  2. thank you sir ,its really helpful for my vivas examination ! if possible then plz make some more notes like this. thanku.....

    ReplyDelete
  3. How I can change the OK and Cancel by a Yes or a NO

    ReplyDelete
  4. How I can change the OK and Cancel by a Yes or a NO

    $("#loadValida").click(function(){
    var confirmar = confirm("Se encuentran validados los datos ?);

    if (confirmar == true){
    document.location.href="/controlador/avanza/{{$datos}}";

    }else{
    alert('Verifique datos');
    }
    });

    ReplyDelete
  5. thnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    ReplyDelete
  6. Thanks Nikhil Sir. please keep it Up""""""""""""""""""""""""""""""""""""""""""""""""}

    ReplyDelete
  7. Yes,You are absolutely right.Traditional javascript knowledge is still required and forms a core part of a web developer.The input we get through prompt will be in string.

    JavaScript Training
    AngularJS Training in chennai
    BackboneJS Training in chennai

    ReplyDelete
  8. Helpful and easy to understand explanation.

    ReplyDelete
  9. There are numerous schools which now delicate deceive classes to figure out whether you will maturate it fit for you.java

    ReplyDelete
  10. Thank you for this valuable information. I have got some important suggestions from it. Get your business to the next level in simple steps.
    ERP Software Solutions in Chennai

    ReplyDelete
  11. HI,
    Thanks foe sharing the very informative article.
    http://kosmiktechnologies.com/msbi/

    ReplyDelete
  12. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    dotnet training in bangalore

    ReplyDelete
  13. Good Information about microsoft, thanks for sharing nice post on MSBI Online Training Hyderabad

    ReplyDelete
  14. Hey,


    Hip Hip Hooray! I was always told that slightly slow in the head, a slow learner. Not anymore! It’s like you have my back. I can’t tell you how much I’ve learnt here and how easily! Thank you for blessing me with this effortlessly ingestible digestible content.

    I have written a java software that need to open images (a colorblind simulator). The standard javafx class to open images (Image) only supports a limited amount of formats (jpg, png and gif). Open sources external libraries exist on the web to open other image formats What I would like is to be able to test at run time if the additional library is installed, if yes use it to decode the image. But if not, use the standard java Class to at least open the supported formats. The reason is simple. The user could download my jar file and run it with the standard java installed and nothing else. If (s)he wants to open additional formats, (s)he can install additional libraries.

    How can we achieve this in Java? Somehow I would like to have the analogous of the function dlopen in C.


    Anyways great write up, your efforts are much appreciated.

    Thanks & Regards,
    Morgan

    ReplyDelete
  15. I strongly believe that there will be great opportunities for those who looked into this area, thanks much for creating and posting here...
    Best Online Software Training Institute | HTML5 CSS3 Training

    ReplyDelete
  16. i really impressed with your blog, thanks for giving such a nice post.. Keep sharing!!
    DevOps Online Training


    ReplyDelete
  17. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    Devops online training
    Devops certification training
    Devops online course
    Devops training course

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Thanks for sharing such a valuable information...
    devops training bangalore - eCare Technologies located in Marathahalli - Bangalore, is one of the best DevOps Training institute with 100% Placement support. DevOps Training in Bangalore provided by
    DevOps Certified Experts and real-time Working Professionals with handful years of experience in real time DevOps Projects.
    http://www.ecaretechnologies.info/DevOps-Training-Institutes-in-Bangalore.html

    ReplyDelete
  20. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming (7+ years) will ensure that we will deliver our best in python training in vijayawada. , and we believe that no one matches us in this context.

    ReplyDelete
  21. remain conscious, the outcome is the equivalent; a sparkle of expectation was made with that revelation. modvigil

    ReplyDelete

  22. Thank you so much for sharing this blog, such a nice information u have posted. i'm so thankful for your blog .
    core java training in hyderabad.

    ReplyDelete
  23. Excellent blog thank you for the info

    data science courses

    ReplyDelete
  24. Excellent blog thank u sharing the useful info.....
    data science courses

    ReplyDelete
  25. I strongly believe that there will be great opportunities for those who looked into this area, thanks much for creating and posting here...
    core java training in hyderabad.

    ReplyDelete
  26. Mind Q Systems provides AWS training in Hyderabad & Bangalore.AWS training designed for students and professionals. Mind Q Provides 100% placement assistance with AWS training.

    Mind Q Systems is a Software Training Institute in Hyderabad and Bangalore offering courses on Testing tools, selenium, java, oracle, Manual Testing, Angular, Python, SAP, Devops etc.to Job Seekers, Professionals, Business Owners, and Students. We have highly qualified trainers with years of real-time experience.
    AWS

    ReplyDelete
  27. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Business Analytics Course in Hyderabad | Artificial Intelligence Course in Hyderabad | Business Analytics Training in Hyderabad

    ReplyDelete
  28. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.
    Business Analytics Training in Hyderabad
    Artificial Intelligence Course in Hyderabad
    Business Analytics Course in Hyderabad

    ReplyDelete
  29. What a really awesome post this is. Truly, one of the best posts I've ever witnessed to see in my whole life. Wow, just keep it up.
    Data Science Training in Hyderabad | Data Science Course in Hyderabad

    ReplyDelete
  30. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

    SAP HCM Online Training

    SAP HCM Classes Online

    SAP HCM Training Online

    Online SAP HCM Course

    SAP HCM Course Online

    ReplyDelete
  31. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you...
    Data Science Training in Bangalore

    ReplyDelete
  32. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. alert security

    ReplyDelete
  33. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. security guard training near me

    ReplyDelete
  34. Islam, one among largest religions in the world also the one that is misunderstood all time. There are several sources including political, economic & media, framed Islam as misleading religion. And the truth about muslims are always hidden from the light.
    Truth About Islam
    Truth About Muslims
    Islamic Sharia Law
    Women In Islam
    Why Wear Hijab
    Quran And Science
    Muslims Are Not Terrorists
    Polygamy In Islam
    the holy book of islam

    ReplyDelete
  35. Hey Loved the post! Great article and congrats on Reaching the To 50! I will be back to visit often

    ReplyDelete
  36. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    It courses

    ReplyDelete
  37. Business Intelligent Analyst: In order to check the current status of a company or where it stands, a Business Analyst uses data and looks for patterns, business trends, relationships and comes up with a visualization and report. data science course syllabus

    ReplyDelete
  38. Thanks for sharing this information. I really Like Very Much.
    angular js online training

    ReplyDelete
  39. Make video for show this difference. If you post it on tiktok, you can get tiktok likes from here https://soclikes.com/buy-tiktok-likes

    ReplyDelete
  40. Thank you for this post. I want to share with you useful info too. Here is the site https://viplikes.in where you can buy twitter followers for your profile by low price

    ReplyDelete
  41. Great to become visiting your weblog once more, it has been a very long time for me. Pleasantly this article that i've been sat tight for such a long time. I will require this post to add up to my task in the school, and it has identical theme along with your review. Much appreciated, great offer.
    data scientist course

    ReplyDelete
  42. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works
    Best Institute for Data Science in Hyderabad

    ReplyDelete
  43. Really Nice Information It's Very Helpful All courses Checkout Here.
    best data science course

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. You totally coordinate our desire and the assortment of our data.
    artificial intelligence course

    ReplyDelete
  46. Thank you for sharing this wonderful site; it is quite informative. Your writing ability is excellent; you should continue to write blogs of this nature.

    Digital Marketing Training In Telugu
    Digital Marketing Means In Telugu
    digital marketing online course in telugu

    ReplyDelete
  47. Always so interesting to visit your site. What a great info, thank you for sharing. this will help me so much in my learning...

    AWS Training in Hyderabad

    ReplyDelete
  48. Very informative article, To know more - SEO Training in Bangalore

    ReplyDelete
  49. Potential customers are searching for your product or service online. An experienced SEO Bali will devise a successful strategy that gives you the chance to appear above your competitors in search engine results. Our strategy will not only promote your website to more customers in Google and other search engines but will optimise landing pages to increase conversions and generate sales.

    ReplyDelete
  50. Really, this article is truly one of the best in article history. I am a collector of old "items" and sometimes read new items if I find them interesting. And this one that I found quite fascinating and should be part of my collection. Very good work!

    Business Analytics Course

    ReplyDelete
  51. It is late to find this act. At least one should be familiar with the fact that such events exist. I agree with your blog and will come back to inspect it further in the future, so keep your performance going.

    Best Data Science Courses in Bangalore

    ReplyDelete

  52. Looking for a site where you can earn good knowledge and much more information like you want ?
    So here is webthi here you can get the perfect and accurate according to new trends.

    ReplyDelete
  53. I would love to read your posts again and again. Also, I will wait for your next post. AppSquadz is helping businesses with their concerns get in touch with us for more help. Also visit: flutter development company

    ReplyDelete
  54. Our online assignment writing service. guarantees that every paper is written from scratch and is 100% original. Whenever you order from Assignmentworkhelp, you are guaranteed to receive only original college assignments, done by the best assignment writers. You are being assured to book your order now
    online assignment help

    ReplyDelete
  55. Apart from generic Furniture Bali designs that we mass manufacture and distribute globally, we do our best to experiment with furniture designs that we either get through our commercial or hospitality customers or we simply mix-match or tinker around with some of the well-known furniture designs till we end up with some striking furniture pieces . We developed expertise in working furniture made from both metal, bamboo & wood and we began our journey as a manufacturer of industrial furniture. That’s the point where our interest piqued and we relentlessly began pursuing the holy grail of furniture manufacturing – developing expertise in intricate furniture styles like vintage furniture, art deco furniture, villa furniture, restaurant furniture, hotel contemporary, Balinese furniture, and bamboo designs.

    ReplyDelete
  56. Through this Digital Marketing Institute in Panchkula, you will become an expert in modules such as SEO, Social Media Marketing, PPC, Analytics, Content, Mobile, and Email Marketing. Our Social Media Marketing and PPC courses in Panchkula have trained end number of students. Work on real-world projects, learn the latest tools, and attend masterclasses led by the Google and Facebook certified team.

    - Get hands-on training on live projects!
    - Upgrade your resume
    - Get prepared for your dream job.
    - 120+ hours of high-quality training.
    - 10+ live projects.
    - 25+ digital marketing tools and platforms.

    ReplyDelete
  57. Through this Digital Marketing Institute in Panchkula, you will become an expert in modules such as SEO, Social Media Marketing, PPC, Analytics, Content, Mobile, and Email Marketing. Our Social Media Marketing and PPC courses in Panchkula have trained end number of students.

    ReplyDelete
  58. Through this Digital Marketing Training Institute in Panchkula you will become an expert in modules such as SEO, Social Media Marketing, PPC, Analytics, Content, Mobile, and Email Marketing. Our Social Media Marketing and PPC courses in Panchkula have trained end number of students. Work on real-world projects, learn the latest tools, and attend masterclasses led by the Google and Facebook certified team.


    - Get hands-on training on live projects!
    - Upgrade your resume
    - Get prepared for your dream job.
    - 120+ hours of high-quality training.
    - 10+ live projects.
    - 25+ digital marketing tools and platforms.

    ReplyDelete
  59. Bangaloredigitalmarketing provides the best Digital Marketing courses in bangalore with certification
    and placements in jayanagar, marathahalli
    https://bangaloredigitalmarketing.com/
    https://bangaloredigitalmarketing.com/digital-marketing-courses-in-bangalore/
    https://bengalurudigitalmarketing.blogspot.com/

    ReplyDelete
  60. If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job.
    brand consulting agency

    ReplyDelete
  61. I have been searching to find a comfort or effective procedure to complete this process and I think this is the most suitable way to do it effectively. data science course in mysore

    ReplyDelete
  62. Thank you for the post. I will definitely comeback. data scientist course in surat

    ReplyDelete
  63. I need to to thank you for this very good read!! I definitely loved every little bit of it. I have you bookmarked to check out new things you post… data science course in mysore

    ReplyDelete
  64. Thanks for sharing the post. Now I clarified my doubts on these methods.
    best digital marketing agency in dubai

    ReplyDelete
  65. thank you for sharing this. who want to learn online courses. visit:Online With Certification

    ReplyDelete
  66. Develop technical skills and become an expert in analyzing large sets of data by enrolling for the Best Data Science course in Bangalore. Gain in-depth knowledge in Data Visualization, Statistics, and Predictive Analytics along with the two famous programming languages and Python. Learn to derive valuable insights from data using skills of Data Mining, Statistics, Machine Learning, Network Analysis, etc, and apply the skills you will learn in your final Capstone project to get recognized by potential employers.


    Data Science Course in Bangalore

    ReplyDelete
  67. Gain mastery over the core principles of data science and get ready to work with top companies. Get acquainted with the bright and exciting future of data science by enrolling in the best data science institute in Bangalore. Learn to empower more meaningful business decisions by representing data with tools of visualization.

    Data Science in Bangalore

    ReplyDelete
  68. Venture into the world of opportunities with Data Science in Bangalore and learn the valuable skills to demonstrate your capabilities to tackle this evolution of huge data. Avail benefits like Placement Assistance, Mock Interview, and Resume Building support from the placement team. Enroll now and learn Python, Tableau, SQL, Hadoop, and Spark to become a specialist in Data Science.

    Data Science Course in Delhi

    ReplyDelete
  69. This is a great post. Your blog is very informative I have learned a lot of information from your blog. We are top Website Development Company in India.



    If anyone is looking for Web Development services contact today: +91 9501406707

    ReplyDelete
  70. "This is the kind of content that makes the internet a better place."
    our sclinbio.com

    ReplyDelete
  71. Thank you for sharing this insightful post! Your detailed explanation of the reasons behind java.io.FileNotFoundException is incredibly helpful. The examples provided make it easy to understand the scenarios where this exception may occur, and your clear solutions offer valuable guidance for resolution. I appreciate how you've covered various situations, from file not found to accessibility issues and potential conflicts with other programs.
    visit- Java vs. Other Programming Languages: Which Course Should You Take?

    ReplyDelete
  72. very informative, thanks for sharing this information. Python Classes In Pune

    ReplyDelete
  73. Thanks for sharing excellent information. Your website has very useful information. I’m impressed by the details that you have in this article.

    Workday Training in Hyderabad

    ReplyDelete