close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Trying to populate form field with autocomplete from 2 different arrays

Thread began 8/01/2013 11:14 am by stephen287384 | Last modified 8/05/2013 2:42 pm by Ray Borduin | 804 views | 3 replies |

stephen287384

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

Sign in to reply to this post

Jason ByrnesWebAssist

i dont think that will be posible, though you could edit the inital array to use both sources, so instead of using:

var tags = [ <?php do { ?>"<?php echo $row_rsCategories['category']; ?>",<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?> ];


to populate the array, use:
var tags = [ <?php do { ?>"<?php echo $row_rsCategories['category']; ?>",<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?><?php do { ?>"<?php echo $row_rsKeywords['keyword']; ?>",<?php } while ($row_rsKeywords = mysql_fetch_assoc($rsKeywords)); ?>];

Sign in to reply to this post

stephen287384

Hi Jason, yes i had it working like that but not really what i was after. After thinking about what i'm trying to achieve, i might try a diferent approach.

Sign in to reply to this post

Ray BorduinWebAssist

We ended up getting this working in a Premier Support ticket. The solution was to combine both recordset results into an array. That way we could sort the array alphabetically and loop on it to populate the auto-complete.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...