Question

these are my two textboxes

<input name="temp" type="text" id="authnames" />
<input name="qot" type="text" id="qid"  value=""/>

and i am gettting value in the first textbox, i can see it in screen (the one with id authnames)

now i need to pass that value to via jquery/ajax to a new php page and need to retrieve it there below is my jquery/ajax code, and see the way i am passing it, is this the correct way, coz idont think i am getting any value in autocompletequote.php, what am i doing wrong?

$(document).ready(function(){
    $("#qid").autocomplete({
        source: "autocompletequote.php",
        minLength: 1,
        data: { postcode: $("#authnames").val(),
        type: "post",
        dataType: "json", 
        success: function(data) {
            console.log( data );
            console.log("hi");
        }
    },
    select: function (event, ui) {
        var label = ui.item.label;
        var value = ui.item.value;
        //alert(label);
        alert(value);
    }
});
});

there are the two codes i used to retrieve value value in "authnames"

$author = $_POST['postcode'];

and

$author = $_GET['postcode'];

is this correct too?

i have written 2 queries in autocomplete.php

one query do not need value of $author and other needs value of $author,

first query is working fine second is not working its returning null

please help me

Was it helpful?

Solution 2

finally i got the answer i just changed the code to this

<script>
var label;
var value;
 $(document).ready(function(){

                $("#tag").autocomplete({
                    source:'autocomplete.php',
                    minLength:1,
                    select: function (event, ui) 
                    {
                         label = ui.item.label;
                         value = ui.item.value;
                        $("#authnames").val(value);
                        console.log("hi");

                        //alert(label);
                        alert(value);

                        $("#qid").autocomplete({
                       source:'autocompletequote.php?postcode='+value,
                       minLength:1,
                       select: function (event, ui) 
                       {
                        var label1 = ui.item.label;
                        var value1= ui.item.value;

                        console.log("hi");

                        //alert(label);
                        //alert(value);
                       }


                   });

                    }


                });



            });




</script>

now everything is A OK

OTHER TIPS

I think your syntax for the auto-complete is wrong.

it has to follow jquery-autocomplete 's syntax.

The data is actually a function after the autocomplete.

so to fix ure code, to go towards what u r doing is..

$(document).ready(function(){

$("#qid").autocomplete
({
   source:"autocompletequote.php",
   minLength:1,
   select: function (event, ui) 
   {
    var label = ui.item.label;
    var value = ui.item.value;
    //alert(label);
    alert(value);
    $.ajax({
       url: "autocompletequote.php",
       data: { "Myvariablename" : $("#authnames").val() } ,
       type:"post",
       dataType:"json", 
       success:function(data)
       {
           console.log( data );
           console.log("hi");
       }
     });
   }

  });
 });

Or i am mis-understanding ure purpose

In PHP

$authname = $_POST["Myvariablename"];

EDITED :

To pass an extra query, or custom query, the source attribute has to be a function like so

$("#qid").autocomplete({
  source: function(request, response) {
    $.getJSON("autocompletequote.php", { "Myvariablename" : $("#authnames").val(), "someothervarialble" : xxx }, 
              response);
  },
  minLength: 1,
  select: function(event, ui){
    // your action or futher ajax code goes here.
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top