Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php and ajax on select option

<select name="allbooks" id="allbooks">
  <option value="none" ></option>
  <option value="allbooks" >All Books</option>
</select>
<div id="show">
  <!-- ITEMS TO BE DISPLAYED HERE -->
</div>



<script src="jquery-1.9.1.min.js"></script> <!-- CHANGE THE JQUERY FILE DEPENDING ON THE VERSION YOU HAVE DOWNLOADED -->
<script type="text/javascript">
  $(document).ready(function(){ /* PREPARE THE SCRIPT */
    $("#allbooks").change(function(){ /* WHEN YOU CHANGE AND SELECT FROM THE SELECT FIELD */
      var allbooks = $(this).val(); /* GET THE VALUE OF THE SELECTED DATA */
      var dataString = "allbooks="+allbooks; /* STORE THAT TO A DATA STRING */

      $.ajax({ /* THEN THE AJAX CALL */
        type: "POST", /* TYPE OF METHOD TO USE TO PASS THE DATA */
        url: "get-data.php", /* PAGE WHERE WE WILL PASS THE DATA */
        data: dataString, /* THE DATA WE WILL BE PASSING */
        success: function(result){ /* GET THE TO BE RETURNED DATA */
          $("#show").html(result); /* THE RETURNED DATA WILL BE SHOWN IN THIS DIV */
        }
      });

    });
  });
</script>
  
  if(!empty($_POST["allbooks"])){
  /* DO YOUR QUERY HERE AND GET THE OUTPUT YOU WANT */
  echo $output; /* PRINT THE OUTPUT YOU WANT, IT WILL BE RETURNED TO THE ORIGINAL PAGE */
}
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel 8 - get values of url query strings in controller 
Php :: match php 
Php :: how to add two string in php 
Php :: php unit expect exception 
Php :: error laravel 404 in server 
Php :: how to excluse csrf in a route laravel 
Php :: how to check if query is successfully inserted laravel 
Php :: laravel_login 
Php :: in date function + 1 month and - 1 day in php 
Php :: woocommerce set default shipping country 
Php :: get page templete 
Php :: laravel relation with limit 
Php :: php creating a subdomain automatically in cpanel 
Php :: time characters php 
Php :: Clear any previous error php 
Php :: console.log for php 
Php :: Laravel Max Helper Function 
Php :: to enable php in apache 
Php :: laravel collection makeHidden 
Php :: validar tipo de imagen php 
Php :: laravel hash password sample 
Php :: how to disable a button in a blade file 
Php :: turn off wordpress user list exposed 
Php :: consumir soap php 
Php :: check if config exist laravel 
Php :: how to fetch days old records php mysql 
Php :: php array_diff 
Php :: laravel collection isNotEmpty 
Php :: send data with url in php 
Php :: php show hide td 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =