Using jQuery to pass hidden field based on SELECT box selection

Using jQuery to pass hidden field based on SELECT box selection

Is there a jQuery way to using the "starts with" from the SELECT box to pass a variable to a hidden field? Here's what I have for the script to far, but I need it to only look for the first letter, really. 

For example, if the user selects "Keyboards - Acoustic Piano", we need "KeyboardMag" to pass through in the hidden field "referralCode". 

  1. $( document ).ready(function() {
  2.     var refcode={
  3.           Guitars   : "GuitarsMag",
  4.           Keyboards   : "KeyboardMag",
  5.           Drums       : "DrumMag",
  6.           Microphones : "MusicMag"
  7.     }
  8.     $("#productsMusical").change(function(e){ 
  9.           $('[name="referralCode"]').val(  refcode[ $(this).val() ] )
  10.     })
  11. });

From the form:
  1. <input name="referralCode" value="" id="referralCode" type="hidden">

  2. <select id="productsMusical" name="productsMusical">
  3.   <option value="" selected="selected">--Please Select--</option>
  4.   <option value="Guitars - Acoustic">Guitars - Acoustic</option>
  5.   <option value="Guitars - Electric">Guitars - Electric</option>
  6.   <option value="Guitars - Bass">Guitars - Bass</option>
  7.   <option value="Keyboards - Acoustic Piano">Keyboards - Acoustic Piano</option>
  8.   <option value="Keyboards - Digital Piano">Keyboards - Digital Piano</option>
  9.   <option value="Keyboards - Synth">Keyboards - Synth</option>
  10.   <option value="Drums - Acoustic">Drums - Acoustic</option>
  11.   <option value="Drums - Electric">Drums - Electric</option>
  12.   <option value="Drums - Band">Drums - Band</option>
  13.   <option value="Microphones - Vocal">Microphones - Vocal</option>
  14.   <option value="Microphones - Vocal Headset">Microphones - Vocal Headset</option>
  15.   <option value="Microphones - Instrument">Microphones - Instrument</option>
  16. </select>