{"id":2120,"date":"2017-08-09T01:08:00","date_gmt":"2017-08-09T01:08:00","guid":{"rendered":"http:\/\/javascript-tutor.net\/?page_id=2120"},"modified":"2018-04-08T02:20:30","modified_gmt":"2018-04-08T02:20:30","slug":"a-selection-box","status":"publish","type":"page","link":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/","title":{"rendered":"A Selection Box"},"content":{"rendered":"<p>You can create a selection box in JavaScript that allows the user to select a certain category of items, in this example, books.<\/p>\n<p>In this example, we create a function called loadHtml) to load a web\u00a0page from a selection list. As this selection list is situated in a form, we need to add the parameter form in the aforementioned function, loadHtml(form).<\/p>\n<p>In the script, we use the if keyword to load a particular web page selected by the user. The syntax is<\/p>\n<pre>if (form.list.selectedIndex==n) location=\"abc.html\"<\/pre>\n<p>*The object list is a selection box and the selectedIndex(n) property indicates the position of the item in the selection box. The location property points to a particular web page.<\/p>\n<h3>The Script<\/h3>\n<pre>&lt;SCRIPT LANGUAGE=\"JavaScript\"&gt;\r\n\r\nfunction loadHtml(form){\r\nif (form.list.selectedIndex==0) location=\"art.html\"\r\nif (form.list.selectedIndex==1) location=\"astro.html\"\r\nif (form.list.selectedIndex==2) location=\"bestsell.html\"\r\nif (form.list.selectedIndex==3) location=\"business.html\"\r\nif (form.list.selectedIndex==4) location=\"children.html\"\r\nif (form.list.selectedIndex==5) location=\"computer.html\"\r\nif (form.list.selectedIndex==6) location=\"health.html\"\r\nif (form.list.selectedIndex==7) location=\"mystery.html\"\r\nif (form.list.selectedIndex==8) location=\"horror.html\"\r\nif (form.list.selectedIndex==9) location=\"nonfic.html\"\r\nif (form.list.selectedIndex==10) location=\"romance.html\"\r\nif (form.list.selectedIndex==11) location=\"science.html\"\r\nif (form.list.selectedIndex==12) location=\"scific.html\"\r\nif (form.list.selectedIndex==13) location=\"self.html\"\r\nif (form.list.selectedIndex==14) location=\"sports.html\"\r\nif (form.list.selectedIndex==15) location=\"travel.html\"\r\nif (form.list.selectedIndex==16) location=\"young.html\"\r\nif (form.list.selectedIndex==17) location=\"music.html\"\r\n\r\n}\r\n&lt;\/Script&gt;\r\n<\/pre>\n<p>We use the <strong>Select<\/strong> keyword to create the list box, as follows:<\/p>\n<pre>&lt;SELECT NAME=\"list\" size=\"4\"&gt;\r\n&lt;OPTION&gt;Art and Drawing\r\n&lt;OPTION&gt;Astronomy\r\n&lt;OPTION&gt;Best Sellers\r\n&lt;OPTION&gt;Business &amp; Investment\r\n&lt;OPTION&gt;Children Books\r\n&lt;OPTION selected&gt;Computer &amp; Internet\r\n&lt;OPTION&gt;Health &amp; Fitness\r\n&lt;OPTION&gt;Mystery\r\n&lt;OPTION&gt;Horror &amp; Thriller\r\n&lt;OPTION&gt;Non Fiction\r\n&lt;OPTION&gt;Romance\r\n&lt;OPTION&gt;Science &amp; Nature\r\n&lt;OPTION&gt;Science Fiction\r\n&lt;OPTION&gt;Self Improvement\r\n&lt;OPTION&gt;Sports &amp; Games\r\n&lt;OPTION&gt;Travel\r\n&lt;OPTION&gt;Young Readers' Corner\r\n&lt;OPTION&gt;Music\r\n&lt;\/SELECT&gt;\r\n<\/pre>\n<p>*the size indicates the number of items to be displayed.<\/p>\n<p>Finally, we need to create a button to allow the user to select an item. The syntax is as follows:<\/p>\n<p>&lt;Input TYPE=&#8221;button&#8221; NAME=&#8221;button&#8221; Value=&#8221;OK&#8221; onClick=&#8221;loadHtml(this.form)&#8221;&gt;<\/p>\n<p>View the <a href=\"http:\/\/javascript-tutor.net\/Javascript_Samples\/advsearchbox.html\">\u00a0Selection Box<\/a> here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can create a selection box in JavaScript that allows the user to select a certain category of items, in this example, books. In this example, we create a function called loadHtml) to load a web\u00a0page from a selection list. As this selection list is situated in a form, we need to add the parameter &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Selection Box&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2120","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"description\" content=\"Creating a selection box in JavaScript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"Creating a selection box in JavaScript\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:modified_time\" content=\"2018-04-08T02:20:30+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\",\"name\":\"A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2017-08-09T01:08:00+00:00\",\"dateModified\":\"2018-04-08T02:20:30+00:00\",\"description\":\"Creating a selection box in JavaScript\",\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Selection Box\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Creating a selection box in JavaScript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/","og_locale":"en_US","og_type":"article","og_title":"A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"Creating a selection box in JavaScript","og_url":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_modified_time":"2018-04-08T02:20:30+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/","url":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/","name":"A Selection Box - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2017-08-09T01:08:00+00:00","dateModified":"2018-04-08T02:20:30+00:00","description":"Creating a selection box in JavaScript","breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/a-selection-box\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"A Selection Box"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=2120"}],"version-history":[{"count":4,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2120\/revisions"}],"predecessor-version":[{"id":2538,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2120\/revisions\/2538"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}