Getting URL value into clone select box

Getting URL value into clone select box

I have a form where i'm asking room details and how many children. Then if it is >0 how old are they.

When the form is sent to show the list of rooms I want the values selected to be in the select box with what is selected but it is displaying the default 1.

How do I get the URL parameter to put the selected value from the returned URL into the cloned select boxes?

Thanks

  1. age1 =  getUrlParameter('age1');
  2. age2 =  getUrlParameter('age2');
  3. age3 =  getUrlParameter('age3');


  4. $('#numberOfChildren').change(function(){
  5. $('#ach-age').html('');
  6.     var $div = $('#add_select'), //Select the appending div
  7.         $select = $('<select/>', {name : 'childAges', class: 'form-control ach-c-age'}), //Create a template
  8.         index = $(this).val(); //get the number of select
  9.     
  10.     
  11.    
  12.     $div.empty(); //Erase old select
  13.     
  14.     if(!index) return; //Stop the code if the number of child is 0
  15.     
  16.     for(var i=1; i<14; i++){ //Maximum child age
  17.         var $option = $('<option/>', {text : i, value : i});//Create the option element
  18.         $select.append($option);//Append to the template
  19. $('#ach-age').html('Child age/s');
  20.     }
  21. for(var u=0; u<index; u++){//Get the number of child
  22.         var $clone = $select.clone(); //Clone the template
  23.         $clone.attr('name', 'age'+(u+1)).appendTo($div); //Change its id and append to the container
  24.     }
  25. }).trigger('change');