How to use php to feed data to jQuery autocomplete? -


this continuation of earlier post. unfortunately, solutions posted didn't work , follow questions weren't addressed. in case because generous respondents didn't notice had replied, i'm reposting problem.


i'm trying build form text fields , text areas have autocomplete.

i've used formidable plugin wordpress build form. i'm using jquery autocomplete plugin autocomplete part.

after implementing suggestions of 1 of respondents, code looks this:

<script>  $(document).ready(function(){  <?php global $frm_entry_meta;  $entries = $frm_entry_meta->get_entry_metas_for_field(37, $order=''); ?>  var data = new array(); <?php foreach($entries $value){ ?> data.push(unescape('<?php echo rawurlencode($value); ?>');  <?php } ?>  $("#field_name-of-the-school").autocomplete(data); })  </script>  // 37 field id want pull in database,  // , #field_name-of-the-school css id  // text field in form user can enter name of school.  // data field stored in db under field id 37.  // other fields, school id, have own field ids. 

my respondent suggested adding data.push(unescape('<?php echo rawurlencode($value); ?>'); bit. unfortunately, it's still not working.

btw, code in body of page.php, template wordpress uses generate static pages (the form on 1 of these).

i seriously, appreciate , this. if approach dead end (on earlier posts, there 2 other answers on head,) more willing learn new tricks (though pointed relevant learning resource.)

thanks in advance.

i jsut use json_encode , simplify it:

<script>  $(document).ready(function(){    <?php global $frm_entry_meta;    $entries = $frm_entry_meta->get_entry_metas_for_field(37, $order=''); ?>    var data = <?php echo json_encode($entries); ?>;    $("#field_name-of-the-school").autocomplete({source: data}); });  // note missing semicolon @ end of this, added </script> 

of course using above may not waht want if $entries associative array instead of numeric indexed one. if thats case can json_encode(array_values($entries));


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -