Solved

php, autocomplete and scriptaculous

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simplest php form 3 63
Download a website to hdd 2 51
mysqli 3 22
How to loop through records  using SELET COUNT 2 16
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

867 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

15 Experts available now in Live!

Get 1:1 Help Now