Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:21:38+00:00 2026-06-01T15:21:38+00:00

I am using the autocomplete feature of jQuery UI to create a passive database

  • 0

I am using the autocomplete feature of jQuery UI to create a passive database of associative values. I have three inputs: Lens Type, Lens Design and Lens Material.

All three values are autocomplete, and upon form submit if there are values unique to those inputs they are stored in the database.

What I want to do is return autocomplete values for each input based upon the known input of the previous input. So for example Lens Type a only has Lens Design input’s: c,d,g. Where as if Lens type is set to b then autocomplete would return a,b,e,f.

How would I do this with jQuery UI autocomplete? I already know how to write the database and server side logic but the autocomplete frontend has be stumped.

Edit:
I have worked out a hardcoded method of doing this by the using following java-script:

            $('input.autocompleteme').each( function() {
            var $input = $(this);
            $input.autocomplete({ 
                source: function( request, response ) {

                    var fieldName = $input.attr('id');

                    if ( fieldName.indexOf( "Right" ) !== -1 ) {
                        var lensSide = "Right";
                    }else{
                        var lensSide = "Left";
                    }

                    var LensType = $("#" + "Patient" + lensSide + "EyeLensType").attr("value");
                    var LensDesign = $("#" + "Patient" + lensSide + "EyeLensDesign").attr("value");
                    var LensMaterial = $("#" + "Patient" + lensSide + "EyeLensMaterial").attr("value");
                    var LensCoating = $("#" + "Patient" + lensSide + "EyeLensCoating").attr("value");
                    var LensTints = $("#" + "Patient" + lensSide + "EyeLensTints").attr("value");

                    var serverUrl = "/autocomplete.json?field=" + fieldName + "&LensType=" + LensType + "&LensDesign=" + LensDesign + "&LensMaterial=" + LensMaterial + "&LensCoating=" + LensCoating + "&LensTints=" + LensTints;
                    var term = request.term;

                    lastXhr = $.getJSON( serverUrl, request, function( data, status, xhr ) {
                        response( data );
                    });
                },
                minLength: 2, 
            });
        });

This submits a url to a cakephp function that looks similar to:

    function admin_autocomplete(){
    Controller::loadModel('AutoField');

    $param      = $this->params["url"]["term"];
    $fieldName  = $this->params["url"]["field"];
    $hasParent  = false;
    $output     = array();

    if ($param == ''){
        $this->set("output", NULL);
        return;
    }

    switch ($fieldName){

        case "PatientRightEyeLensType":
        case "PatientLeftEyeLensType":
            $fieldName = "LensType";
        break;

        case "PatientRightEyeLensDesign":
        case "PatientLeftEyeLensDesign":
            $fieldName = "LensDesign";
            $hasParent = "LensType";
        break;

        case "PatientRightEyeLensMaterial":
        case "PatientleftEyeLensMaterial":
            $fieldName = "LensMaterial";
            $hasParent = "LensDesign";
        break;

        case "PatientRightEyeLensCoating":
        case "PatientLeftEyeLensCoating":
            $fieldName = "LensCoating";
            $hasParent = "LensMaterial";
        break;

        case "PatientRightEyeLensTints":
        case "PatientLeftEyeLensTints":
            $fieldName = "LensTints";
            $hasParent = "LensCoating";
        break;

        default:
            die("Field Name is not known");
        break;
    }

    if ($hasParent === false){ // This is the root of the tree.

        $query = array(
            "conditions" => array(
                "type" => $fieldName,
                "parent_id" => NULL,
                "value REGEXP '^$param'"
            ),
            "fields" => array(
                "value"
            ),
        );

        $results = $this->AutoField->find("all", $query);

    }else{

        $parentValue = $this->params["url"][$hasParent];
        $query = array(
            "conditions" => array(
                "type" => $hasParent,
                "value" => $parentValue,
            ),
            "fields" => array(
                "id",
            )
        );

        $results = $this->AutoField->find("all", $query);
        $parentIds = "";
        foreach ($results as $parentId){
            $parentIds .= $parentId["AutoField"]["id"] . ",";
        }

        $parentIds = substr_replace($parentIds ,"",-1);

        $query = array(
            "conditions" => array(
                "type" => $fieldName,
                "parent_id IN ($parentIds)",
                "value REGEXP '^$param'"
            ),
            "fields" => array(
                "value"
            ),
        );

        $results = $this->AutoField->find("all", $query);

    }

    foreach ($results as $result){
        $output[] = $result["AutoField"]["value"];
    }

    $this->set("output", $output); 

}

My Mysql database looks like the following:

--
-- Table structure for table `auto_fields`
--

CREATE TABLE IF NOT EXISTS `auto_fields` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `created` datetime default NULL,
  `modified` datetime default NULL,
  `parent_id` int(11) default NULL,
  `type` varchar(100) default NULL,
  `value` varchar(150) default NULL,
  `count` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `auto_fields`
--

INSERT INTO `auto_fields` (`id`, `created`, `modified`, `parent_id`, `type`, `value`, `count`) VALUES
(1, '2012-04-12 10:51:00', '2012-04-12 10:51:02', NULL, 'LensType', 'Progressive', 0),
(2, '2012-04-12 10:51:00', '2012-04-12 10:51:00', NULL, 'LensType', 'Bifocal', 0),
(3, '2012-04-12 11:55:46', '2012-04-12 11:55:46', 1, 'LensDesign', 'AAA', 0),
(4, '2012-04-12 11:55:46', '2012-04-12 11:55:46', 1, 'LensDesign', 'BBB', 0);

I am sure someone with better Javascript skills than myself would be able to write that side of the UI interaction so that it doesn’t require hard coding of inherited variables.

For me this works as expected with the inheritance being mapped by the switch in the php function. If I can figure out the javascript front end I may write this into a cakephp helper and component.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:21:40+00:00Added an answer on June 1, 2026 at 3:21 pm

    I don’t think there is anything that jQuery UI provides out of the box for this.

    If you have all these values in the client side, you can filter using the callback function to the “source” option while setting up the autocomplete. In the callback function, you would have the logic to see the values in the other autocomplete boxes and then return the filtered set.

    If, on the other hand, you fetch the autocomplete values on the, you can put a similar logic there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test server with a page using jquery autocomplete. The autocomplete feature
I am using autocomplete feature in jquery to show the users list intellisense. for
I am using jquery autocomplete pluguin. Configured to use multiple Values. I set option
I am using the autocomplete feature of jQuery. When I try to retrieve the
I'm using Autocomplete UI . I have some ploblems with results of a database
I'm implementing a Google Suggest like autocomplete feature for tag searching using jQuery's autocomplete.
I am looking for a plugin that provides the autocomplete feature using jQuery Mobile?
I have implemented the Ajax Autocomplete feature in my application using a web service
Interested in using the jQuery UI autocomplete feature to connect with a large MySQL
I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.