Solved

php, autocomplete and scriptaculous

Posted on 2006-06-21
1
1,099 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

Technology Partners: 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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

740 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