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.

125 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. Thanks for your informative article on UFT automation testing tool. Your post helped me to understand the features and functionality of QTP automation testing tool. QTP Course in Chennai | QTP training

    ReplyDelete
  9. Helpful and easy to understand explanation.

    ReplyDelete
  10. Thanks for Sharing the valuable information and thanks for sharing the wonderful article..We are glad to see such a wonderful article..
    QTP Training in Chennai | QTP Training Institute in Chennai | QTP Training

    ReplyDelete
  11. Hi, the information you provided here is very informative and useful for me. If anyone interested to learn AngularJS Training reach GangBoard. MSBI Training | Hadoop Training

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

    ReplyDelete

  13. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write.
    Thanks for sharing !
    tanki online 2 | 2048 game online

    ReplyDelete
  14. 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
  15. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp providers in chennai.

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

    ReplyDelete
  17. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
    office 2010 professional plus key deutsch

    ReplyDelete
  18. Good post and I like it very much. By the way, anybody try this app development company for iOS and Android? I find it is so professional to help me boost app ranking and increase app downloads.

    ReplyDelete
  19. Your website content nice nice and interesting to observe.
    Internet Marketing Dienstleistungen

    ReplyDelete
  20. 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
  21. Good Information about microsoft, thanks for sharing nice post on MSBI Online Training Hyderabad

    ReplyDelete
  22. 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
  23. 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

  24. Its Very a useful post to everyone and learn AWS from best IT training institute TO register Now
    Amazon web Services Training
    Salesforce training in Hitech city
    Salesforce training in Hyderabad

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


    ReplyDelete
  26. Thank you for sharing such a nice and interesting blog with us. i have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle. please keep on updates. hope it might be much useful for us. keep on updating...
    AWS Training in Chennai
    AWS Course in Chennai
    Aws Certification in Chennai
    German Courses in Chennai
    best german classes in chennai
    German language training in chennai

    ReplyDelete
  27. 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

  28. Nuvigil smart drug is the trade name for Armodafinil smart drug and is the enantiopure compound of Modafinil. There are a number of health benefits that the use of Nuvigil smart drug has to offer to its users. So, you can buy Nuvigil online. The use of the smart drug is safe and has no health issues attached to its usage. In the year 2006, the FDA approved the use of generic Nuvigil smart drug to be used to treat a number of mental issues. Buy Nuvigil online as the use of Nuvigil smart drug has long effect when compared to other smart drugs. This is mainly because Armodafinil smart drug has a longer half-life than the other smart drugs. Therefore more and more people are depending on Nuvigil smart drug to carry on their daily routine smoothly.
    Buy Nuvigil online

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

    ReplyDelete
  30. Thanks for the blog. I especially loved the content and the great stuff here. Also read this:Nursing Assignment Help

    ReplyDelete

  31. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    angular js online training
    best angular js online training
    top angular js online training

    ReplyDelete
  32. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    workday studio online training
    best workday studio online training
    top workday studio online training

    ReplyDelete
  33. 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
  34. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. best devops online training

    ReplyDelete
  35. 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
  36. keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
    digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

    ReplyDelete
  37. Wow! Really a nice blog. Thank you so much for you effort.
    Best online training

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

    ReplyDelete

  39. 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
  40. Excellent blog thank you for the info

    data science courses

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

    ReplyDelete
  42. 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
  43. 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
  44. Attend The Machine Learning course Bangalore From ExcelR. Practical Machine Learning course Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Machine Learning course Bangalore.
    Machine Learning course Bangalore

    ReplyDelete
  45. Blockchain Course in Bangalore with 100% placement. We are the Best Blockchain Course Institute in Bangalore. Our Agile testing course and Certification courses are taught by working professionals who are experts in Blockchain.

    Blockchain Training in Bangalore

    Blockchain course in bangalore

    Blockchain in bangalore

    Blockchain classes in bangalore

    Blockchain course institute in bangalore

    Agile testing course and Certification course syllabus

    best Blockchain course

    Blockchain course centers

    ReplyDelete
  46. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    servicenow online training
    best servicenow online training
    top servicenow online training

    ReplyDelete
  47. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    microservices online training
    best microservices online training
    top microservices online training

    ReplyDelete
  48. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    servicenow online training
    best servicenow online training
    top servicenow online training

    ReplyDelete
  49. Pretty article! I found some useful information in your blog....

    so here we provide,

    We provide you with flexible services and complete hybrid network solutions. It can provide your organisation with exceptional data speeds, advanced external security protection, and high-resilience by leveraging the latest SD-WAN and networking technologies to monitor, manage and strengthening your organisation’s existing network devices.

    https://www.quadsel.in/networking/>
    https://twitter.com/quadsel/
    https://www.linkedin.com/company/quadsel-systems-private-limited/
    https://www.facebook.com/quadselsystems/

    #quadsel #network #security #technologies #managedservices #Infrastructure #Networking #OnsiteResources #ServiceDeskSupport #StorageServices #WarrantyAMCServices #datacentersolutions #DataCenterBuild #EWaste #InfraConsolidation #DisasterRecovery #NetworkingServices #ImagingServices #MPS #Consulting #WANOptimisation #enduserservices

    ReplyDelete
  50. 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
  51. 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
  52. You have written a very informative article with great quality content and well laid out points. I agree with you on many of your views and you've got me thinking.
    Best Data Science training in Mumbai

    Data Science training in Mumbai

    ReplyDelete
  53. 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
  54. Great article like this require readers to think as they read. I took my time when going through the points made in this article. I agree with much this information.
    SAP training in Kolkata
    SAP training Kolkata
    Best SAP training in Kolkata
    SAP course in Kolkata
    SAP training institute Kolkata

    ReplyDelete
  55. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    Data Science Institute in Bangalore

    ReplyDelete
  56. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.

    SAP Online Training

    SAP Classes Online

    SAP Training Online

    Online SAP Course

    SAP Course Online

    ReplyDelete
  57. 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
  58. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.

    SAP HANA Online Training

    SAP HANA Classes Online

    SAP HANA Training Online

    Online SAP HANA Course

    SAP HANA Course Online

    ReplyDelete
  59. I see some amazingly important and kept up to length of your strength searching for in your on the site
    Data Science Course in Bangalore

    ReplyDelete
  60. 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
  61. Thanks for sharing this information. I really Like Very Much.
    devops online training

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

    ReplyDelete
  63. 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
  64. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.


    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

    ReplyDelete
  65. 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
  66. Hey Loved the post! Great article and congrats on Reaching the To 50! I will be back to visit often

    ReplyDelete
  67. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    data science course in indore

    ReplyDelete

  68. Fantastic article I ought to say and thanks to the info. Instruction is absolutely a sticky topic. But remains one of the top issues of the time. I love your article and look forward to more.
    360DigiTMG Data Science Training Institute in Bangalore

    ReplyDelete

  69. Additionally, this is an excellent article which I truly like studying. It's not everyday I have the option to see something similar to this.
    Data Science Course In Bangalore With Placement

    ReplyDelete
  70. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.
    360digitmg

    ReplyDelete
  71. 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
  72. 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
  73. Thanks for sharing this information. I really Like Very Much.
    angular js online training

    ReplyDelete
  74. 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