Solved

php, autocomplete and scriptaculous

Posted on 2006-06-21
1
1,085 Views
Last Modified: 2012-05-05
Funny this title looks very similar.  Yes it is.  After typing the question I figured that I should break the question up, as they were different.

I'm using the scriptaculous library for my ajax stuff and I would like to do more then one field on the page, however the snippet that I have been using was only written for one field.  I would like to make it so that I could call functions rather then pages so doesnt anyone have a clue on how to do that?  I've tried <?=acQuery()?> but nothing.

<input type="text" id="rep" name="_field" tabindex="1" value="">
<input  type="hidden" name="field" value="-1">
<div id="autocomplete_choices" class="autocomplete"></div>
<script type="text/javascript" language="javascript">
                    new Ajax.Autocompleter('rep','autocomplete_choices','acQuery.php', {paramName: "q",minChars: 1, afterUpdateElement: updateHidden });
</script>
0
Comment
Question by:iceman19330
1 Comment
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 16958245
If you want to use more fields, just copy the code, like so:
<input type="text" id="rep" name="_field" tabindex="1" value="">
<input  type="hidden" name="field" value="-1">
<div id="autocomplete_choices" class="autocomplete"></div>
<script type="text/javascript" language="javascript">
                 new Ajax.Autocompleter('rep','autocomplete_choices','acQuery.php', {paramName: "q",minChars: 1, afterUpdateElement: updateHidden });
</script>
<input type="text" id="rep2" name="_field2" tabindex="1" value="">
<input  type="hidden" name="field2" value="-1">
<div id="autocomplete_choices2" class="autocomplete"></div>
<script type="text/javascript" language="javascript">
                 new Ajax.Autocompleter('rep2','autocomplete_choices2','acQuery.php', {paramName: "q",minChars: 1, afterUpdateElement: updateHidden });
</script>

If you want to call functions instead of the whole php page, use something like this in your php page:

// Grap command/function to execute (default if not set or set with bogus value)
$valid_commands('function1', 'function2');
$command = (array_key_exists('cmd', $_REQUEST) ? $_REQUEST['cmd'] : 'function1');      
if (in_array($command, $valid_commands))
                $content = $command();
        else
                $content = function1();

and then use your script like so:
<input type="text" id="rep" name="_field" tabindex="1" value="">
<input  type="hidden" name="field" value="-1">
<div id="autocomplete_choices" class="autocomplete"></div>
<script type="text/javascript" language="javascript">
                 new Ajax.Autocompleter('rep','autocomplete_choices','acQuery.php?cmd=function1', {paramName: "q",minChars: 1, afterUpdateElement: updateHidden });
</script>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now