1
votes

I'm using 2 autocomplete in my php form.1st for getting company names (from mysql) & 2nd for getting product names of selected company (from mysql). For example if i select company "A" then i need to get all the product name of company "A" only in 2nd autocomplete textfield.

Note : (This is possible in select menu but i'm using autocomplete because i have a record of more then 200 companies)

My javascript code for autocomplete :

<script>
$(document).ready(function() {
$("input#companyname").autocomplete({
source: [
          <?php
          while($rs = mysql_fetch_array($res))
          {
            $title = $rs['title'];
          ?>
          "<?php echo $title; ?>" <?php echo ", "; ?>   
          <?php
          }
          ?> 
         ]
});
});
</script>
3
What exactly is your question? Your title and body of your message don't seem to add up. - ralfe
@ralfe My question is same like when u select country name from one drop down list, in 2nd drop down list u get the cities of that country.But in my case i m doing this with autocomplete. - user1176151

3 Answers

1
votes

take a look at the documentation for this JQuery .autocomplete pluging at http://www.devbridge.com/projects/autocomplete/jquery/ . So , an example would be:

var a = $('#query').autocomplete({ 
    serviceUrl:'service/autocomplete.ashx',
    minChars:2, 
    delimiter: /(,|;)\s*/, // regex or character
    maxHeight:400,
    width:300,
    zIndex: 9999,
    deferRequestBy: 0, //miliseconds
    params: { country:'Yes' }, //aditional parameters
    noCache: false, //default is false, set to true to disable caching
    // callback function:
    onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
    // local autosugest options:
    lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values 
  });

You will see that under params, you can specify additional data to send with the AJAX query. So, in your case, you would want to send the company name/id from the company input field with the autocomplete request for the products field. So you would have something like:

<input id='company_name' />
...
var company_name = document.getElementById('company_name').value;
...
params: { company: company_name }

Hope that helps.

0
votes

You don't need a submit button but you will need a postback or an asynchronous callback--the submit button just does the first. If you wanted it to be similiar with the other autocomplete, look up Ajax calls from jquery.

-1
votes

This is the wrong way to go about it. You should create a separate PHP file that will out put your database results as JSON. Then you can call upon this JSON file to do your auto complete in jquery.

As far as no Submit button you can try

$("input#companyname").keypress({
     // do your thing here
});