{"id":284,"date":"2025-08-25T04:32:51","date_gmt":"2025-08-25T04:32:51","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=284"},"modified":"2025-08-27T06:32:49","modified_gmt":"2025-08-27T06:32:49","slug":"javascript-dialogue-box","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=284","title":{"rendered":"javascript dialogue box"},"content":{"rendered":"\n<p>In JavaScript, there are <strong>three main types of built-in dialogue boxes<\/strong> (pop-ups) you can use in the browser:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Alert Box<\/strong> (just shows a message)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>alert(\"Hello! This is an alert box.\");\n<\/code><\/pre>\n\n\n\n<p>Shows a simple message with an <strong>OK<\/strong> button.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Confirm Box<\/strong> (asks user Yes\/No type choice)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = confirm(\"Do you want to continue?\");\nif (result) {\n  console.log(\"User pressed OK\");\n} else {\n  console.log(\"User pressed Cancel\");\n}\n<\/code><\/pre>\n\n\n\n<p> Returns <strong>true<\/strong> if user clicks <strong>OK<\/strong>, <strong>false<\/strong> if Cancel.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Prompt Box<\/strong> (asks user for input)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let name = prompt(\"What is your name?\");\nif (name) {\n  console.log(\"Hello, \" + name + \"!\");\n} else {\n  console.log(\"User did not enter a name.\");\n}\n<\/code><\/pre>\n\n\n\n<p> Returns the text entered by the user, or <code>null<\/code> if Cancel is clicked.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p> Example combining all:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alert(\"Welcome!\");\n\nlet proceed = confirm(\"Do you want to enter your name?\");\nif (proceed) {\n  let username = prompt(\"Please enter your name:\");\n  alert(\"Hello, \" + username + \"!\");\n} else {\n  alert(\"Okay, maybe next time!\");\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>In JavaScript, there are three main types of built-in dialogue boxes (pop-ups) you can use in the browser: 1. Alert Box (just shows a message) Shows a simple message with an OK button. 2. Confirm Box (asks user Yes\/No type choice) Returns true if user clicks OK, false if Cancel. 3. Prompt Box (asks user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-internet-networking"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284"}],"version-history":[{"count":1,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":285,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions\/285"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}