title: How to change form action attribute value based on selection?
body: <p>I've looked at countless examples on here and not sure what I'm doing wrong. I'm trying to change the form action based on the selected value from a dropdown menu.</p>
  
  <p>Basically, the HTML looks like this:</p>
  
  <pre><code>&lt;form id="storetable" autocomplete="off" action="" method="post"&gt;
  &lt;label&gt;STORE:&lt;/label&gt;
    &lt;input type="text" list="storeID" name="store" placeholder="Choose a store..." required&gt;
         &lt;datalist id="storeID"&gt;
            &lt;option value="cwb_coins"&gt;Causeway Bay&lt;/option&gt;
            &lt;option value="wc_coins"&gt;Wan Chai&lt;/option&gt;
            &lt;option value="lck_coins"&gt;Lai Chi Kok&lt;/option&gt;
            &lt;option value="tp_coins"&gt;Tai Po&lt;/option&gt;
         &lt;/datalist&gt;
  &lt;/form
  </code></pre>
  
  <p>javascript:</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
      $("#storeID").change(function(){
     var url =  $(this).children(":selected").text(); //get the selected option value
     switch (url) 
    {
     case "cwb_coins":
     $("#storetable").attr('action','cwb_coin_code.php');
     //changing action attribute of form to cwb_coin_code.php
     break;
     case "wc_coins":
     $("#storetable").attr('action','wc_coin_code.php');
     break;
     case "lck_coins":
     $("#storetable").attr('action','lck_coin_code.php');
     break;
     case "tp_coins":
     $("#storetable").attr('action','tp_coin_code.php');
     break;
     default:
         $("#storetable").attr('action', '#');
     }
     }); 
   }); 
  &lt;/script&gt;
  </code></pre>