Q:

How to change form action attribute value based on datalist selection

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. Why won't this work?
Basically, the HTML looks like this:
<form id="storetable" autocomplete="off" action="" method="post">
<label>STORE:</label>
  <input type="text" list="storeID" name="store" placeholder="Choose a store..." required>
       <datalist id="storeID">
          <option value="cwb_coins">Causeway Bay</option>
          <option value="wc_coins">Wan Chai</option>
          <option value="lck_coins">Lai Chi Kok</option>
          <option value="tp_coins">Tai Po</option>
       </datalist>
</form

javascript 
<script>
    $(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', '#');
   }
   }); 
 }); 
</script>

A:

You are setting the wrong value to the attribute - you need the actual value of the sleected option - not the text content

$(document).ready(function(){
    $("#store").change(function(){
   var url =  $('#store').val(); //get the selected option value
   console.log('action: ' + url);
   switch (url) 
    {
     case "cwb_coins":
      $("#storetable").attr('action','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', '#');
   }
   }); 
 });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="storetable" autocomplete="off" action="" method="post">
<label>STORE:</label>
  <input type="text" id="store" list="storeID" name="store" placeholder="Choose a store..." required>
       <datalist id="storeID">
          <option value="cwb_coins">Causeway Bay</option>
          <option value="wc_coins">Wan Chai</option>
          <option value="lck_coins">Lai Chi Kok</option>
          <option value="tp_coins">Tai Po</option>
       </datalist>
</form>

EDIT - refactored to not even need values on the options - note that when you don't include a value - the value is the option text. This way you can use the selected option's text as the variable value in your switch statement.

$(document).ready(function(){
    $("#store").change(function(){
   var url =  $(this).val(); //get the selected option value

   switch (url) 
    {
     case "Causeway Bay":
      $("#storetable").attr('action','cwb_coin_code.php');
       break;
     case "Wan Chai":
       $("#storetable").attr('action','wc_coin_code.php');
        break;
     case "Lai Chi Kok":
        $("#storetable").attr('action','lck_coin_code.php');
         break;
     case "Tai Po":
        $("#storetable").attr('action','tp_coin_code.php');
        break;
     default:
       $("#storetable").attr('action', '#');
   } 
   console.log('action: ' + $('#storetable').attr('action'));
   }); 
   
     
 });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="storetable" autocomplete="off" action="" method="post">
<label>STORE:</label>
  <input type="text" id="store" list="storeID" name="store" placeholder="Choose a store..." required>
       <datalist id="storeID">
          <option>Causeway Bay</option>
          <option>Wan Chai</option>
          <option>Lai Chi Kok</option>
          <option>Tai Po</option>
       </datalist>
</form>

