Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php, autocomplete and scriptaculous

Posted on 2006-06-21
1
Medium Priority
?
1,103 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 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

972 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