title: js pass variables in function call
body: <p>I'm building my first website and I think this is a stupid question, but I'm stuck. I have an ajax call to a script that runs a query and gives an array with some information.</p>
  
  <p>The ajax-call is seperated in a function.
  I can't pass into the function variables with the value of an input.</p>
  
  <p>With a static string/int, it works:</p>
  
  <pre><code>$("#searchIt").click(function(){    
      var inputbranche = $('#branche').val(); #pass the value of select
      var inputplz = $('#plz').val();         #pass the value of input
      window.history.replaceState(null, null, "?branche="+inputbranche+"&amp;plz="+inputplz); //this works fine with the variables
      $('#fulllink').val(window.location.href);
      $('#sm').attr('data-url', window.location.href);
      if(searches == 0) {
          scrollTo("#topscroll");
      } else {
          scrollTo("*[data-resultnumber='1']");
      }
      searchCompanies('tischler', '44444'); //&lt;---- here is the problem: if I use here inputbranche and inputplz, it´s not working...
  
  });
  
  
  function searchCompanies(branche, plz) {
      searches++;
      var shownbranchename = $('#branchename').val();
      $.ajax({
              url: "url/to/script",
              type: "GET",
              data:'wheretostart=0&amp;branche='+branche+'&amp;plz='+plz,
              success: function(data){
                  var count = 0;
                  if(data['success'] == 1) {
                      while(data[count] != 0 ) {
                          if(jQuery.inArray(data[count]['id'], shownIDs) == -1) {
                              var txt = "&lt;div data-resultnumber='"+number+"' data-companyid='"+data[count]['id']+"' class='col-sm-6 col-md-4 p0'&gt;&lt;div class='box-two proerty-item'&gt;&lt;div class='item-thumb'&gt;&lt;a href='property-1.html' &gt;&lt;img src='assets/img/demo/property-3.jpg'&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class='item-entry overflow'&gt;&lt;h5&gt;&lt;a href='property-1.html'&gt; "+data[count]['companyname']+" &lt;i class='fa fa-check-circle' aria-hidden='true'&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h5&gt;&lt;div class='dot-hr'&gt;&lt;/div&gt;&lt;span class='pull-left'&gt;&lt;b&gt; Branche :&lt;/b&gt; "+data[count]['branches']+" &lt;/span&gt;&lt;h3 class='pull-right'&gt;&lt;span class='fa fa-star checked'&gt;&lt;/span&gt;&lt;span class='fa fa-star checked'&gt;&lt;/span&gt;&lt;span class='fa fa-star checked'&gt;&lt;/span&gt;&lt;span class='fa fa-star'&gt;&lt;/span&gt;&lt;span class='fa fa-star'&gt;&lt;/span&gt;&lt;/h3&gt;&lt;p style='display: none;'&gt;"+data[count]['shorttext']+"&lt;/p&gt;&lt;div class='property-icon'&gt;&amp;nbsp;&lt;i class='fa fa-map-marker' aria-hidden='true'&gt;&lt;/i&gt; "+data[count]['companyzipcode']+" | &lt;i class='fa fa-users' aria-hidden='true'&gt;&lt;/i&gt; "+data[count]['employeecount']+" | &lt;i class='fa fa-envelope' aria-hidden='true'&gt;&lt;/i&gt; 355  &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;";
                              $("#list-type").append(txt);
                              shownIDs.push(data[count]['id']);
                          }
                          count++;
                          number++;
                          if(shownbranchename !== branche) {
                              $('#branchename').text(branche);
                          }
                      } 
                  } else {
                      var txt = data['errors'];
                      $("#list-type").append(txt);
              }
          }
      });
  }
  </code></pre>
  
  <p>HTML with the search:</p>
  
  <pre><code> &lt;fieldset&gt;
       &lt;div class="row"&gt;
            &lt;div class="col-xs-12"&gt;
                 &lt;div class="form-group"&gt;
                      &lt;label for="branche"&gt;Branche:&lt;/label&gt;&lt;br&gt;
                      &lt;select name="branche" id="branche" class="form-control" title="Branche"&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "architekten") {echo "selected";} ?&gt; value="architekten"&gt;Architekten&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "dachdecker") {echo "selected";} ?&gt; value="dachdecker"&gt;Dachdecker&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "geruestbauer") {echo "selected";} ?&gt; value="geruestbauer"&gt;Gerüstbauer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "klempner") {echo "selected";} ?&gt; value="klempner"&gt;Klempner&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "maler_und_lackierer") {echo "selected";} ?&gt; value="maler_und_lackierer"&gt;Maler und Lackierer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "maurer_und_betonbauer") {echo "selected";} ?&gt; value="maurer_und_betonbauer"&gt;Maurer und Betonbauer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "metallbauer") {echo "selected";} ?&gt; value="metallbauer"&gt;Metallbauer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "Ofen-_und_Luftheizungsbauer") {echo "selected";} ?&gt; value="Ofen-_und_Luftheizungsbauer"&gt;Ofen- und Luftheizungsbauer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "schornsteinfeger") {echo "selected";} ?&gt; value="schornsteinfeger"&gt;Schornsteinfeger&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "strassenbauer") {echo "selected";} ?&gt; value="strassenbauer"&gt;Straßenbauer&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "tischler") {echo "selected";} ?&gt; value="tischler"&gt;Tischler&lt;/option&gt;
                           &lt;option &lt;?php if($_GET['branche'] == "zimmerer") {echo "selected";} ?&gt; value="zimmerer"&gt;Zimmerer&lt;/option&gt;
                       &lt;/select&gt;
                 &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-12"&gt;
                 &lt;div class="form-group"&gt;
                      &lt;label for="plz"&gt;Postleitzahl:&lt;/label&gt;  
                      &lt;input type="number" id="plz" name="plz" class="form-control" &lt;?php if($_GET['plz'] != null) {$temp = $_GET['plz']; echo "value='$temp'";} else {echo "placeholder='Postleitzahl'";} ?&gt;&gt;
                 &lt;/div&gt;
            &lt;/div&gt;
       &lt;/div&gt;
   &lt;/fieldset&gt;
  
   &lt;fieldset&gt;
       &lt;div class="row"&gt;
            &lt;div class="col-xs-12"&gt;  
                 &lt;button type="button" id="searchIt" class="button btn largesearch-btn" value="Search" type="submit"&gt;Search&lt;/button&gt;
            &lt;/div&gt;  
       &lt;/div&gt;
    &lt;/fieldset&gt;  
  </code></pre>
  
  <p>Here is the php code, hopefully this helps...</p>
  
  <pre><code>&lt;?php
  header('Content-type: application/json');
  ini_set("display_errors", 1);
  session_start();
  $return = array();
  /* PHP lookup: Looks up the matching Companies in the DB */
  require_once ('../global_konfi.php');
  require_once ('../functions/functions.php');
  $pdo = new  pdo ("mysql:host=dddd; dbname=" . $mysql['database'], 
  $mysql['user'], $mysql['password']);
  if(brancheIsBranche($_GET['branche']) == true) {
      $plz = $_GET['plz'];
      $limitstart = $_GET['wheretostart'];
      $perpage = "15";
      $statement = $pdo-&gt;prepare("SELECT COUNT(*) as anzahl FROM handwerksbetriebe WHERE general_branche = :branche AND general_visible = 1 AND general_state = 1 AND assignment_zipcoderange LIKE :zipcode LIMIT $limitstart, $perpage");
      $statement-&gt;bindValue(':branche', $_GET['branche']);       
      $statement-&gt;bindValue(':zipcode', "%;$plz;%", PDO::PARAM_STR);       
      if ($statement-&gt;execute()) { 
          $row = $statement-&gt;fetch();
          if ($row['anzahl'] &gt;= 1) {
              $statement = $pdo-&gt;prepare("SELECT * FROM handwerksbetriebe WHERE general_branche = :branche AND general_visible = 1 AND general_state = 1 AND assignment_zipcoderange LIKE :zipcode LIMIT $limitstart, $perpage"); #statemetn vorbereiten
              $statement-&gt;bindValue(':branche', $_GET['branche'], PDO::PARAM_STR);       
              $statement-&gt;bindValue(':zipcode', "%;$plz;%", PDO::PARAM_STR);  
              $statement-&gt;execute();
              $count = 0;
              $temp = array();
              while($row = $statement-&gt;fetch()) {
                  $temp = [
                      'id' =&gt; $row['general_id'],
                      'shorttext' =&gt; $row['general_shorttext'],
                      'companyname' =&gt; $row['general_title'],
                      'verified' =&gt; $row['general_verified'],
                      'assignmentcount' =&gt; $row['general_assignmentcount'],
                      'employeecount' =&gt; $row['general_employeecount'],
                      'averagerating' =&gt; $row['general_averagerating'],
                      'companyzipcode' =&gt; $row['contact_zipcode'],
                      'branches' =&gt; $row['general_branche'],
                  ];
                  array_push($return, $temp);
                  $count++;
              }
              $return['errors'] = "0";
              $return['success'] = "1";
          } else {
          $return['errors'] = "noexecute";
          $return['success'] = "0";
          }
  
      } else {
          $return['errors'] = "noexecute";
          $return['success'] = "0";
      }
  } else { 
  $return['errors'] = "norealinput";
  $return['success'] = "0";
  }
  echo json_encode($return);
  </code></pre>