A
A
Alexander Ruzhevich2016-09-09 19:43:50
PHP
Alexander Ruzhevich, 2016-09-09 19:43:50

ajax php sql form?

Good day, there is a form

<form method="post" action="search_ajax.php">

    <input type="text" class="search_input" name="search" id="search" class='search_box'/>
  
        <select class="search_in" name="search_in" id="search_in"> 
        <option value='' selected='selected'>Искать по</option>
        <option VALUE="id">Номер</option>
        <option VALUE='status'>Статус</option>
        <option VALUE='master'>Мастер</option> 
    </select>
  
    <input type="submit" value="Поиск" class="search_button" /><br />

</form>


I have a form handler

if (isset($_POST['search_in']))  {
  $s_i = $_POST['search_in'];
  echo $s_i;

}

if (isset($_POST['search']))  {
    $s = $_POST['search'];
  echo $s;
}

$query_to_db = mysql_query("SELECT * FROM equipment WHERE $s_i LIKE '%$s%'");


there is ajax input fields

<script type="text/javascript">
$(function(){
  $("#search").keyup(function(){
     var search = $("#search").val();
     $.ajax({
       type: "POST",
       url: "search_ajax.php",
       data: {"search": search},
       cache: false,                                 
       success: function(response){
          $("#resSearch").html(response);
       }
     });
     return false;
   });
});

</script>


and select

<script type="text/javascript">
$(function(){
  
  
    $("#search_in").change(function(){
        $.ajax({
            type : 'POST',
            url : 'search_ajax.php',
            data : { search_in: $(this).val() },
            success: function(response){
          $("#resSearch").html(response);
       }
        });
    })
}


);

</script>


individually, they work, but if they are put together, then only select works. The question is how to pass data only together?? for example, I chose select (a search criterion) and then you enter data into input and only now that the data is transmitted.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-09-09
@slo_nik

Good evening.
Combine two js scripts.
Hang submit on the form
Serialize the form like this or like that
Submit
Process the data on the server
to work with the forms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question