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

  • Home
  • SEARCH
  • 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 6360119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:36:27+00:00 2026-05-24T23:36:27+00:00

I have a set of three combo boxes (drop downs) that are populated by

  • 0

I have a set of three combo boxes (drop downs) that are populated by PHP with values from a database. I’ve tested these combo boxes by changing the echoed Submit button to type='submit', and loading the php page itself. They work without a hitch in this fashion.

However, when I load the Ajax page, the submit button refuses to trigger the Ajax function. I have tested the page by creating a set of static combo boxes with html, and in this case the Ajax fires without a hitch. Yet using the PHP created combo boxes do not trigger the Ajax.

I’m hoping someone can shed some light on what the problem is concerning my code.

The HTML & jQuery:

<div id="gallery_container">
    <ul class="new_arrivals_gallery"></ul>
    <div class="pagination"></div>
</div>
<script type="text/javascript" src="js/libs/jquery-1.6.1.min.js"></script> 
<script>

$(document).ready(function() {

    function loadData(imgFamily, imgClass, imgGender){
        $.ajax
        ({
            type: "GET",
            url: "filter_test.php",
            data: {imgFamily:imgFamily, imgClass:imgClass, imgGender:imgGender},
            success: function(data) {
                $("#gallery_container").html(data);
            },
        });
    }
    loadData(1);  // For first time page load default results

    //Bind keypress event to Ajax call
    $('.filter').keypress(function(e) {
        if(e.keyCode == 13) {
            var imgFamily = $('#imgFamily').attr('value');
            var imgClass = $('#imgClass').attr('value');
            var imgGender = $('#imgGender').attr('value');
            //Fetch the images
            loadData(imgFamily, imgClass, imgGender);
        }
    });

    //Bind the click event to Ajax call on submit
    $("#submit").click(function(){
        var imgFamily = $('#imgFamily').attr('value');
        var imgClass = $('#imgClass').attr('value');
        var imgGender = $('#imgGender').attr('value');
        //Fetch the images
        loadData(imgFamily, imgClass, imgGender);
    })
});

The PHP (Although I don’t believe the problem lies here):

I’m showing only one combo box to save space, and since they’re all the same

// Queries for combo boxes
$imgFamily_query = "SELECT DISTINCT imgFamily FROM images WHERE $clause";
$imgClass_query = "SELECT DISTINCT imgClass FROM images WHERE $clause";
$imgGender_query = "SELECT DISTINCT imgGender FROM images WHERE $clause";


// Create the form and combo boxes
echo "<form name='refine' action=''>
        <fieldset><legend>Refine Results</legend>";

    // imgFamily combo box
    if($imgFamily_result = mysql_query($imgFamily_query))  {
      if($imgFamily_success = mysql_num_rows($imgFamily_result) > 0) {
        // Start combo-box
        echo "<label for='imgFamily' id='imgFamily_label'>Choose a family</label>\n
            <select class='filter' id='imgFamily' name='imgFamily'>\n
            <option value='1'></option>\n";
        // For each item in the results...
        while ($imgFamily_row = mysql_fetch_array($imgFamily_result))
          // Add a new option to the combo-box
          echo "<option value='$imgFamily_row[imgFamily]'>$imgFamily_row[imgFamily]</option>\n";
        // End the combo-box
        echo "</select>\n";
      } else { echo "No results found."; }
    } else { echo "Failed to connect to database."; }


    // Add a submit button to the form
    echo "</fieldset>
        <fieldset><input type='button' name='submit' value='submit' id='submit'></fieldset>
    </form>";

Thanks very much for any help.

  • 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-05-24T23:36:28+00:00Added an answer on May 24, 2026 at 11:36 pm

    You insert the form and thereby overwrite the elements to which the submit-event is bound. You should re-execute the code that binds the events after you have inserted the new form.

    A cleaner way would be to return a JSON object or XML containing just the modified information, and update your current form instead of inserting a whole new one, but that will be more work.

    function loadData(imgFamily, imgClass, imgGender){
        $.ajax
        ({
            type: "GET",
            url: "filter_test.php",
            data: {imgFamily:imgFamily, imgClass:imgClass, imgGender:imgGender},
            success: function(data) {
                $("#gallery_container").html(data);
    
                bindEvents(); // <---- Call it here
            },
        });
    }
    
    // Separate function
    function bindEvents()
    {
        //Bind keypress event to Ajax call
        $('.filter').keypress(function(e) {
            if(e.keyCode == 13) {
                var imgFamily = $('#imgFamily').attr('value');
                var imgClass = $('#imgClass').attr('value');
                var imgGender = $('#imgGender').attr('value');
                //Fetch the images
                loadData(imgFamily, imgClass, imgGender);
            }
        });
    
        //Bind the click event to Ajax call on submit
        $("#submit").click(function(){
            var imgFamily = $('#imgFamily').attr('value');
            var imgClass = $('#imgClass').attr('value');
            var imgGender = $('#imgGender').attr('value');
            //Fetch the images
            loadData(imgFamily, imgClass, imgGender);
        })
    }
    
    $(document).ready(function() {
    
        loadData(1);  // For first time page load default results
    
        bindEvents(); // <---- And here (where your code originally was).
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which is using a set of three combo boxes. I
I have a set of three vectors: x, y, and z that I want
I have a three tier set-up. Someone suggested I should get the ConnectionString from
I have a table that has three different date columns, so I set each
I have tried to set up combo boxes in the gridview but all the
I have a combo box in which I set up an ItemTemplate that looks
I have a custom control that has several text boxes and combo boxes in
I have two combo boxes set to same store combo1 xtype: 'combo', store: client_store,
I have a window form that has a couple of combo boxes. What I
I have two dependent combo-boxes and the value of second one is populated after

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.