SO - 18351921

by Gauthaman Sahadevan

HTML

<label class="page1">SELECT A STATE:</label>
<div class="tooltips" title="Please select the country that the customer will primarily be served from">
  <select id="country" name="country" placeholder="Phantasyland">
    <option></option>
    <option>Goa</option>
    <option>Maharashtra</option>
    <option>Rajasthan</option>
    <option>Gujrat</option>
    <option>MadhyaPradesh</option>
  </select>
</div>
<br />
<br />
<label class="page1">Location</label>
<div class="tooltips" title="Please select the city that the customer is primarily to be served from.">
  <select id="location" name="location" placeholder="Anycity"></select>
</div>

JavaScript

jQuery(function($) {

  // bind change event to select
  $('#location').on('change', function() {
    var url = $(this).val(); // get selected value
    if (url) { // require a URL
      window.location = url; // redirect
    }
    return false;
  });

  var hashtable = {};
  hashtable['GOA ASF'] = 'http://stackoverflow.com/';
  hashtable['Goa LPG Plant'] = 'http://google.com/';
  hashtable['AKOLA IRD'] = 'http://yahoo.com/';
  hashtable['AURANGABAD LPG PLANT'] = 'http://yahoo.com/';
  hashtable['WADALA I  TERMINAL'] = 'http://yahoo.com/';
  hashtable['AJMER LPG PLANT'] = 'http://yahoo.com/';
  hashtable['AJMER TERMINAL'] = 'http://yahoo.com/';
  hashtable['AWA-SALAWAS PIPELINE PROJ'] = 'http://yahoo.com/';
  hashtable['AHMEDABAD NWZ LPG'] = 'http://yahoo.com/';
  hashtable['AHMEDABAD NWZ RETAIL'] = 'http://yahoo.com/';
  hashtable['AHMEDABAD RETAIL RO'] = 'http://yahoo.com/';
  hashtable['BAKANIA RIL'] = 'http://google.com/';
  hashtable['BHOPAL DSRO'] = 'http://google.com/';
  hashtable['BHOPAL RRO'] = 'http://google.com/';

  var locations = {
    'Goa': ['GOA ASF', 'Goa LPG Plant'],
    'Maharashtra': ['AKOLA IRD', 'AURANGABAD LPG PLANT', 'WADALA I  TERMINAL'],
    'Rajasthan': ['AJMER LPG PLANT', 'AJMER TERMINAL', 'AWA-SALAWAS PIPELINE PROJ'],
    'Gujrat': ['AHMEDABAD NWZ LPG', 'AHMEDABAD NWZ RETAIL', 'AHMEDABAD RETAIL RO'],
    'MadhyaPradesh': ['BAKANIA RIL', 'BHOPAL DSRO', 'BHOPAL RRO']

  }

  var $locations = $('#location');
  $('#country').change(function() {
    var country = $(this).val(),
      lcns = locations[country] || [];

    var html = $.map(lcns, function(lcn) {
      return '<option value="' + hashtable[lcn] + '">' + lcn + '</option>'
    }).join('');
    $locations.html(html)
  });
});