Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this should work (untested, but shows you the idea):</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var zone1 = new Array("london", "manchester", "spain", "paris"); var zone2 = new Array("newyork", "toronto", "los angeles", "vancouver"); var zone3 = new Array("delhi", "seoul", "moscow", "dhaka"); var zones = {}; var zoneLabels = {}; zoneLabels.europe = "Europe"; zoneLabels.northamerica = "North America"; zoneLabels.asia = "Asia"; zones.europe = zone1; zones.northamerica = zone2; zones.asia = zone3; function validateForm(){ var x=document.forms["myForm"]["fname"].value; for (i in zones){ var zone = zones[i]; for(j in zone){ if( x == zone[j]){ alert("you are in " + zoneLabels[i]); return false; } } } alert("try again"); return false; } &lt;/script&gt; &lt;title&gt;test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="myForm" action="" onsubmit="return validateForm()" method="post"&gt; Enter your City: &lt;input type="text" name="fname"&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>if you want to map the continent properties of the zones object to custom labels, you could define a second object (I edited the code above)</p> <p>UPDATE: </p> <p>If you want to add more zones, you should add a new zone array:</p> <pre><code>var zone4 = new Array("canberra","perth"); </code></pre> <p>Add this to the zones object:</p> <pre><code>zones.australia = zone4; </code></pre> <p>And add an entry to the zoneLabels object:</p> <pre><code>zoneLabels.australia = "Australia"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload