Solved

php, autocomplete and scriptaculous

Posted on 2006-06-21
1
1,100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 …

752 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