Trying to populate form field with autocomplete from 2 different arrays
I have a form with 2 fields "what" and "area". I have auto-complete working when there are 2 arrays, one for each field however i need the first field "what" to use data from 2 different arrays. Is this possible?
//This works
<form........
<input name="what" id="what" type="text" size="45" />
<input name="area" id="area" type="text" size="45" />
....../form>
<script>
var tags = [ <?php do { ?>"<?php echo $row_rsCategories['category']; ?>",<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?> ];
$( "#what" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
<script>
var tags3 = [ <?php do { ?>"<?php echo $row_rsDirectory['suburb']; ?>, <?php echo $row_rsDirectory['postcode']; ?> ",<?php } while ($row_rsDirectory = mysql_fetch_assoc($rsDirectory)); ?> ];
$( "#area" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags3, function( item ){
return matcher.test( item );
}) );
}
});
</script>
//This doesn't work
<form........
<input name="what" id="what" type="text" size="45" />
<input name="area" id="area" type="text" size="45" />
....../form>
<script>
var tags = [ <?php do { ?>"<?php echo $row_rsCategories['category']; ?>",<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?> ];
$( "#what" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
<script>
var tags2 = [ <?php do { ?>"<?php echo $row_rsKeywords['keyword']; ?>",<?php } while ($row_rsKeywords = mysql_fetch_assoc($rsKeywords)); ?> ];
$( "#what" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags2, function( item ){
return matcher.test( item );
}) );
}
});
</script>
<script>
var tags3 = [ <?php do { ?>"<?php echo $row_rsDirectory['suburb']; ?>, <?php echo $row_rsDirectory['postcode']; ?> ",<?php } while ($row_rsDirectory = mysql_fetch_assoc($rsDirectory)); ?> ];
$( "#area" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags3, function( item ){
return matcher.test( item );
}) );
}
});
</script>
I have tried changing form field id="what" to class="what" and changing $( "#what" ) to $( ".what" ) to no avail.
I have setup this script on jsfiddle to demonstrate http://jsfiddle.net/KtsXx