php - Javascript location.href doesnt redirect

152

My problem is, that thelocation.href doesn't redirect me to the page that i want. What it does, that the page just reloads.

I tried with button, and withoutpreventdefault(), but still the same problems.

<script type="text/javascript">
  $(document).ready(function(e) 
  {
    $('#submitButton').click(function(e)
    {
      e.preventDefault();
      var iro = $('#iro').val();
      var date_start = $('#date_start').val();
      var date_end = $('#date_end').val();
      location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
    });
  });
</script>

<select name="iro" id="iro" >
  <?php
  $ertek = isset($_POST["iro"]) ? $_POST["iro"] : '' ;
  $get_irok = mysqli_query($kapcs, "SELECT iro_id, iro_nev FROM iro WHERE iro_status = 1 ORDER BY iro_nev ASC");
  if(mysqli_num_rows($get_irok) > 0 )
  {
    while($irok = mysqli_fetch_assoc($get_irok))
    {
      $selected = $ertek == $irok['iro_id'] ? ' selected      echo '<option ' . $selected . ' value="'.$irok['iro_id'].'">'.$irok['iro_nev'].'</option>';
    }
  } 
  ?>
</select>

<td >
<input autocomplete="off" type="text" name="date_start" id="date_start" required value="<?php if(isset($_POST['date_start'])) { echo $_POST['date_start'];} ?>" />
</td>
<td >
<input autocomplete="off" type="text" name="date_end" id="date_end" required value="<?php if(isset($_POST['date_end'])) { echo $_POST['date_end'];} ?>" />
</td>
<td ><button name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>
483

Answer

Solution:

Try location.replace

location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');
671

Answer

Solution:

change this line

 <td ><button name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>

to this

 <td ><input name="submitButton" id="submitButton" type="button">Lekérdezés</button></td>

 $('#submitButton').click(function(e)
    {
      var iro = $('#iro').val();
      var date_start = $('#date_start').val();
      var date_end = $('#date_end').val();
      location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
    });

everything will be fine.

People are also looking for solutions to the problem: php - Can't refresh access token for Google Calendar API on server side

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.