Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==================
- Dependencies
- ==================
- <!-- Auto Suggestion -->
- <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
- <!-- Auto Suggestion js-->
- <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
- ==================
- index.php
- ==================
- //Auto Suggestion
- function split( val ) {
- return val.split( /,\s*/ );
- }
- function extractLast( term ) {
- return split( term ).pop();
- }
- $( "#id" )
- // don't navigate away from the field on tab when selecting an item
- .bind( "keydown", function( event ) {
- if ( event.keyCode === $.ui.keyCode.TAB &&
- $( this ).data( "autocomplete" ).menu.active ) {
- event.preventDefault();
- }
- })
- .autocomplete({
- source: function( request, response ) {
- $.getJSON( "codes/multisuggest.php",{
- term: extractLast( request.term )},
- function( data ) {
- response( $.map( data, function( item ) {
- return {
- value: item.id,
- parentname: item.parentname,
- address: item.address,
- name: item.name,
- mobile: item.mobile,
- due: item.due
- }
- }));
- }
- );
- },
- search: function() {
- // custom minLength
- var term = extractLast(this.value);
- if (term.length < 1) {
- return false;
- }
- },
- focus: function() {
- // prevent value inserted on focus
- return false;
- },
- select: function( event, ui ) {
- $('#id').val(ui.item.value);
- $('#name').val(ui.item.name);
- $('#parentdetail').val(ui.item.parentname+', '+ui.item.address+', Mob- '+ui.item.mobile);
- $('#mobile').val(ui.item.mobile);
- $('#amount').val(ui.item.due);
- $('#div-parentinfo').css('display','block')
- $('#amount').focus()
- /* $('#due_amt').val(ui.item.due)
- if (ui.item.problematic!=1){
- $('#companyautocomplete').removeClass("ui-autocomplete-error");
- document.getElementById('Sendbutton').style.display="block";
- } else {
- $('#companyautocomplete').addClass("ui-autocomplete-error");
- document.getElementById('Sendbutton').style.display="none";
- }*/
- }
- });
- =================
- multisuggest.php
- =================
- <?php
- //database configuration
- //include("../../require/connection.inc.php");
- require_once("../config/config.php");
- $dbHost = HOST;
- $dbUsername = USER;
- $dbPassword = PASS;
- $dbName = DB;
- //connect with the database
- $db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
- //get search term
- $searchTerm = $_GET['term'];
- //get matched data from skills table
- $dataArr = array();
- $query = $db->query("SELECT `student_id`, `studentname`, `parentname`, `mobile`, `address`, `due_amt`,`status` FROM `student_due` WHERE `student_id` LIKE '%".$searchTerm."%' LIMIT 0,10");
- while ($row = $query->fetch_assoc()) {
- $dataArr = array();
- array_push($dataArr,array(
- "id"=>strtoupper($row['student_id']),
- "name"=>ucwords($row['studentname']),
- "parentname"=>ucwords($row['parentname']),
- "address"=>ucwords($row['address']),
- "due"=>$row['due_amt'],
- "mobile"=>$row['mobile'],
- )
- );
- }
- //return json data
- echo json_encode($dataArr);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement