0

I want to do an autocomplete text box function, I have a php variable array say $vararray[]. it holds these values, apple, bat, ball, bed, cat, dog, elephant, fox. Now I want to make a textbox which is enabled with autocomplete textview. when I click on that textbox, I need to populate first 4 values in that array. now as i type in letters the suggestions in the textbox should appear relating to what I type in that textbox like,

for b--> bat,ball,bed

for ba->bat,ball

I don't want to search in database. all the values are readily available in php array variable

is there any method to do that in jquery or ajax or in any other way?

5
  • 4
    take a look at jqueryui.com/autocomplete Commented Jul 8, 2014 at 7:16
  • @Pranav C Balan i referd that first, is there any way to assign my $vararray[] values to var availabletags? i mean to make this happen availabletags = $vararray[]? Commented Jul 8, 2014 at 7:20
  • i did an autocompele for the same from the database using ajax. and it is working good. but this time i dont want to query database. so i dont know how to start Commented Jul 8, 2014 at 7:22
  • okies that's fine but if you would have looked properly at the link which @PranavCBalan shared you would have understood that you don't need to assign values to availableTags array instead you just need to just provide source like this source: YourArrayHere. Commented Jul 8, 2014 at 7:29
  • like this? source : <?php echo $vararray[] ?> Commented Jul 8, 2014 at 7:35

1 Answer 1

1

This is Simple Example of jquery auto complete.

you just have to pass your php array to jquery array. like following:

<?php 
$arr = array(
0=>array(
"id"=> "1",
        "value"=> "Afghanistan",
        "label"=> "Afghanistan"
),
1=>array(
 "id"=> "17",
        "value"=> "Albania",
        "label"=> "Albania"
));
?>

<script type="text/javascript">
var jsArray = <? echo json_encode($arr); ?>;
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.