On selection change replace part of a href

On selection change replace part of a href

Hello there,

I am wondering if anyone can help me with this problem.

Shortly: I have a drop down selection with multiple options, all I want to do is on change of this selection (when user choose another option), it get the value of the new selected option and submit it in href tag instead of another part in this href (replace with part of href).

Problem: everything works fine for the first selection change, but if the user decided to select another option (second, or third time), it doesn't get the new selected option value, it keep the value of the first selected option,
it is like I need a realtime change.

Example:

HTML

  1. <a class="link" href="http://www.google.com/hotel/replacement-part/">Check Availability</a>
  2. <label>Property</label>

  3.        <select id="combobox">
  4.             <option value="noselection">Select your Preferred Hotel</option>
  5.             <option value="A">ABC</option>
  6.             <option value="B">BCD</option>
  7.             <option value="D">DOS</option>
  8.             <option value="C">CAM</option>
  9.         </select>


jQuery

  1. $("#combobox").change(function(){
  2. var hotel = $(this[this.selectedIndex]).val();
  3. $('a').each(function(){
  4.         this.href = this.href.replace ('replacement-part', hotel);
  5.     });

if you change the selection to option value: B, it will replace part of href, but if you then change the selection to another option (e.g. D), it will not replace the replacement part of href to the new value which is D, it just will keep it with the first selection option value which was B.


Thank you.
Best,
EF.