title: Javascript class constructor not working
body: <p>The form I've just created dinamically generates inputs group depending on user 's choice. Once the form will be submitted i'm trying to create a JSON string that will be later on sent to a php file.</p>
  
  <p>I've notice that there is something wrong with the two class constructor (function element, function route)...they are not taking the values of all the properties.</p>
  
  <p>But (I don't know how), the value is shown later in the JSON string.</p>
  
  <p>In order to allow you debugging i've upload files on my server.
  I was not able to make is work on jsfiddle.</p>
  
  <p>This is the url:
  <a href="http://www.alessandrocuria.com/tmp/" rel="nofollow noreferrer">http://www.alessandrocuria.com/tmp/</a></p>
  
  <p>And this is the code</p>
  
  <p></p>
  
  <pre><code>    &lt;form action="" method="post" enctype="multipart/form-data" id="custom-route-form" class="main-form"&gt;
          &lt;div id="book_car" class="title-form current"&gt;
                      &lt;span&gt;
  
                      &lt;/span&gt;
          &lt;/div&gt;
          &lt;div id="message-custom-route"&gt;&lt;/div&gt;
          &lt;div id="book_car_content" class="content-form"&gt;
              &lt;div class="form-block custom-form-block"&gt;
                  &lt;h4&gt;Origin&lt;/h4&gt;
                  &lt;input id="new-route-origin" class="shortcode_input" type="text" value="" name="origine"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-block custom-form-block"&gt;
                  &lt;h4&gt;Destination&lt;/h4&gt;
                  &lt;input id="new-route-destination" class="shortcode_input" type="text" value="" name="destinazione"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-block"&gt;
                  &lt;h4&gt;How many box do you want to create?&lt;/h4&gt;
                  &lt;div class=""&gt;
                      &lt;select id="n_fasce" class="select" name=""&gt;
                          &lt;option value=""&gt;- seleziona -&lt;/option&gt;
                          &lt;option value="1"&gt;1&lt;/option&gt;
                          &lt;option value="2"&gt;2&lt;/option&gt;
                          &lt;option value="3"&gt;3&lt;/option&gt;
                          &lt;option value="4"&gt;4&lt;/option&gt;
                          &lt;option value="5"&gt;5&lt;/option&gt;
                          &lt;option value="6"&gt;6&lt;/option&gt;
                          &lt;option value="7"&gt;7&lt;/option&gt;
                          &lt;option value="8"&gt;8&lt;/option&gt;
                      &lt;/select&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
  
              &lt;div class="clear"&gt;&lt;/div&gt;
  
  
              &lt;div id="price-wrap"&gt;&lt;/div&gt;
  
  
              &lt;div class="form-block custom-form-block submit-costum"&gt;
                  &lt;input id="custom-route-submit" name="modifica" type="submit" class="blue_button form-book" value="Prenota"&gt;
                  &lt;!--&lt;input id="custom-route-submit" class="blue_button form-book" type="submit" value="Continue"&gt;--&gt;
              &lt;/div&gt;
  
  
              &lt;div class="clear"&gt;&lt;/div&gt;
  
          &lt;/div&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
  
  
  
  
  
  $(document).on("ready", function(){
  
      if($('#private-home').length&gt;0){
          loadData();
      }
  
      function loadData(){
          $("#ajaxLoader").show();
          $.ajax({
              type:"POST",
              url:"getItinerari.php"
          }).done(function(itinerario_out){
              console.log(itinerario_out);
              var route = JSON.parse(itinerario_out);
              for(var i in route){
                  var sortableDiv = '&lt;li id="" class="ui-state-default" style=""&gt;'+ route[i].itinerario +'&lt;a href="edit.php?id='+ route[i].it_id +'"&gt;&lt;img src="../images/file_edit.png" alt="Modifica" width="35px" height="auto"&gt;&lt;/a&gt;&lt;a onclick="return deleteConferme();" href="delete.php?it_id='+ route[i].it_id +'"&gt;&lt;img src="../images/delete.png" alt="Elimina" width="35px" height="auto"&gt;&lt;/a&gt;&lt;/li&gt;';
                  $("#sortable").append(sortableDiv);
  
              }
              $("#ajaxLoader").hide();
          });
      }
  
  
  
      function deleteConferme() {
          var result = confirm("Sicuro di voler eliminare questo itinerario?");
          if (!result) {
              return false;
          }
      }
  
  
  
      /*****/
  
      var n_fasce;
      var El_fasce = $('#n_fasce');
      var fasce = [];
      var nameRadio;
  
      var elHtml =
      '&lt;div class="price-box"&gt;'+
          '&lt;h3&gt;Fascia di prezzo&lt;/h3&gt;'+
      '&lt;div&gt;'+
  
      '&lt;input class="" id="fascia_assoluta" name="range_type" value="assoluta" type="radio"&gt;'+
          '&lt;label for="fascia_assoluta"&gt;Prezzo Assoluto&lt;/label&gt;&lt;br&gt;'+
  
      '&lt;input class="" id="fascia_progressiva" name="range_type" value="progressiva" type="radio"&gt;'+
          '&lt;label for="fascia_progressiva"&gt;Prezzo Progressivo&lt;/label&gt;'+
      '&lt;/div&gt;'+
  
      '&lt;div&gt;'+
  
      '&lt;div class="form-block"&gt;'+
          '&lt;h4&gt;DA:&lt;/h4&gt;'+
      '&lt;div class="form-block"&gt;'+
      '&lt;label&gt;DA:&lt;/label&gt;'+
      '&lt;input class="pax_from" type="text"&gt;'+
      '&lt;/div&gt;'+
          '&lt;/div&gt;'+
  
  
          '&lt;div class="form-block"&gt;'+
          '&lt;label&gt;A:&lt;/label&gt;'+
          '&lt;input class="pax_to" type="text"&gt;'+
          '&lt;/div&gt;'+
  
      '&lt;div class="form-block"&gt;'+
      '&lt;label&gt;Prezzo:&lt;/label&gt;'+
      '&lt;input class="price" type="text"&gt;'+
      '&lt;/div&gt;'+
  
          '&lt;/div&gt;'+
          '&lt;/div&gt;';
  
  
  
  
  
      $(El_fasce).on('change', function () {
  
          n_fasce = El_fasce.val();
  
          $('#price-wrap').html('');
  
          for(i=0; i&lt;n_fasce; i++){
  
              var newEle = document.createElement("div");
              newEle.setAttribute("id","element"+i);
              newEle.setAttribute("class","item");
              //newEle.html("&lt;div class='itemCounter'&gt;"+(i+1)+"&lt;/div&gt;"+htmlEl);
              newEle.innerHTML = elHtml;
              $("#price-wrap").append(newEle);
  
              $('#element'+i+' input:radio').each(function (index) {
                  //array[index] = $(this).attr('id');
                  $(this).attr('name', 'range_type'+i);
  
              });
  
              $('.price').attr('class', 'price'+i);
              $('.pax_to').attr('class', 'pax_to'+i);
              $('.pax_from').attr('class', 'pax_from'+i);
  
          }
  
      });
  
      /*****/
  
  
  
  
  
      $('#custom-route-submit').click(function () {
  
  
  
          for(j=0; j&lt;n_fasce; j++){
  
  
  
              var price = $('.price'+j+'').val();
              var pax_from =  $('.pax_from'+j+'').val();
              var pax_to =  $('.pax_to'+j+'').val();
              var route_type = $('input[name="range_type'+j+'"]:checked').val();
  
              /*************/
  
              var tmpElement = new element(price, pax_from, pax_to, route_type);
  
              //var myJsonString = JSON.stringify(tmpElement);
  
              fasce.push(tmpElement);
  
  
          }
  
  
          function element(price, pax_from, pax_to, route_type){
              this.price = price;
              this.pax_from = pax_from;
              this.pax_to = pax_to;
              this.route_type = route_type;
  
          }
  
  
          var origine = $('#new-route-origin').val();
          var destinazione = $('#new-route-destination').val();
  
  
          var route = new route(origine, destinazione, fasce);
  
          function route (origine, destinazione, fasce){
              this.origine = origine;
              this.destinazione = destinazione;
              this.fasce = fasce;
          }
  
  
          var json = JSON.stringify(route);
  
  
  
  
          $.ajax({
              type: 'POST',
              url: 'new-route.php',
              data: {'myjson': json},
              success: function(data) {
                  alert(data);
                  location.replace("new-route.php")
              }
          });
  
  
  
      });
  
  
  
   });
  </code></pre>
  
  <p>Thanks in advance!</p>