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 9152297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:00:30+00:00 2026-06-17T12:00:30+00:00

I am very very new to JQuery and Javascript. I have implemented autocomplete functionality

  • 0

I am very very new to JQuery and Javascript. I have implemented autocomplete functionality that retrieves the data from remote datasource( Mysql + PHP) using jQuery Demo.
I am stuck at the part where the mysql query triggered by the php script is binded to the drop down menu option.

So if I select “comments” from one of the option value, how do I bind it to the search textbox with id=”search_term”.

<label>Select Search parameter:
    <select id="search_parameter" name="search_parameter">
        <option value="Sample name">Sample Name</option>
        <option value="Location name">Location Name</option>
        <option value="comments">Comments</option>
    </select>
</label>

<label> Search Term:<input type="text" id="search_term" required name="search_term" maxlength=30></label>

Now if I select option value as “comments” it should trigger the PHP script that queries the comment field. But I am not sure how do I get the conditional statement into JQuery. I am not getting success with

$(function(){
    $('#search_parameter').change(function(){
        if (this.value == "comments") {
            jQuery(document).ready(function($){
                $('#search_term').autocomplete({source:'search_comments.php', minLength:2});
            });
        else if( this.value =="Sample name") {
            jQuery(document).ready(function($){
                $('#search_term').autocomplete({source:'search_sample_name.php', minLength:2});
            });
}

I am not sure if this is the right approach. I apologize if this question is not worthy of stackoverflow.com.
Thank you

  • 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-17T12:00:31+00:00Added an answer on June 17, 2026 at 12:00 pm

    I would recommend initializing the autocomplete widget once on the input. You can use the option method to set the source when the value of the select element is changed:

    $(function () {
        $("#search_term").autocomplete({
            source: "",
            minLength: 2
        });
    
        $("#search_parameter").change(function () {
            if (this.value === "Sample name") {
                $("#search_term").autocomplete("option", "source", "search_sample_name.php");
            } else if (this.value === "comments") {
                $("#search_term").autocomplete("option", "source", "search_comments.php");
            }
        }).change(); // Trigger the "change" event to set the source correctly the first time.
    });
    

    You can make this even more robust by using a data-* attribute on each option that indicates which source to use:

    HTML:

    <label>Select Search parameter:
        <select id="search_parameter" name="search_parameter">
            <option value="Sample name" data-autocomplete="search_sample_name.php">Sample Name</option>
            <option value="Location name" data-autocomplete="search_locations.php">Location Name</option>
            <option value="comments" data-autocomplete="search_comments.php">Comments</option>
        </select>
    </label>
    

    JavaScript:

    $(function () {
        $("#search_term").autocomplete({
            source: ''
        });
    
        $("#search_parameter").change(function () {
            var selectedSource = $(this).find("option:selected").data("autocomplete");
    
            $("#search_term").autocomplete("option", "source", selectedSource);
        }).change();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to jQuery and javascript. I have an autocomplete box setup
I am very new to jQuery and javascript programming. I have a program below
I'm very new to both JQuery and Javascript. I have an feed, I would
I have done some searching but I am very new to JavaScript and jQuery
I am very new to javascript and have been using the JQuery library quite
I'm very new to JQuery and don't have much experience with javascript at all,
Fairly new to JavaScript and very new to jQuery. Can someone have a look
I am very new at jQuery ... I've used Javascript many times and am
I'm very new to Javascript (and jQuery). My JSFiddle really shows the issue in
Guys i am very new to jQuery. I have started using the auto complete

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.