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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:20:30+00:00 2026-06-18T14:20:30+00:00

My limits. I can not make this to work: I want to make a

  • 0

My limits. I can not make this to work:
I want to make a dynamic select list with jquery and JSON to populate data from database
I see it fetches data in firebug console but it does not populate the select box.
Here’s my view:

<div class="control-group">
            <label class="control-label" for="inputPassword">Grad</label>
            <div class="controls">
                <select name="city" id="city" class="update">
                    <option value="">Odaberi</option>
                    <?php if (!empty($results)) { ?>
                    <?php foreach($results as $row) { ?>
                    <option value="<?php echo $row->city_id; ?>">
                        <?php echo $row->city_name; ?>
                    </option>
                    <?php } ?>
                    <?php } ?>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">Deo grada</label>
            <div class="controls">
            <select name="category" id="category" class="update"
        disabled="disabled">
        <option value="">----</option>
    </select>
            </div>
        </div>

Here is my controller where i call my model:

function update_list(){
$this->marea->update_list();

And, finally my model

function update_list(){
    if (!empty($_GET['id']) && !empty($_GET['value'])) {
        $id = $_GET['id'];
        $value = $_GET['value'];

        try {
            $objDb = new PDO('mysql:host=localhost;dbname=isport', 'root', '');
            $objDb->exec('SET CHARACTER SET utf8');

            $sql = "SELECT *
            FROM `area`
            WHERE `city_id` = ?";
            $statement = $objDb->prepare($sql);
            $statement->execute(array($value));
            $list = $statement->fetchAll(PDO::FETCH_ASSOC);

            if (!empty($list)) {
                $out = array('<option value="">Odaberi</option>');

                foreach($list as $row) {
                    $out[] = '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
                }

                echo json_encode(array('error' => false, 'list' => implode('', $out)));
            } else {
                echo json_encode(array('error' => true));
            }
        } catch(PDOException $e) {
            echo json_encode(array('error' => true));
        }
    } else {
        echo json_encode(array('error' => true));
    }
}

here my ajax:

var formObject = {
    run : function(obj) {
        if (obj.val() === '') {
            obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
        } else {
            var id = obj.attr('id');
            var v = obj.val();
            jQuery.getJSON(SITE +'users/update_list', { id : id, value : v }, function(data) {
                if (!data.error) {
                    obj.next('.update').html(data.list).removeAttr('disabled');
                    return;
                } else {
                    obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
                }
            });
        }
    }
};
$(function() {
    $('.update').live('change', function() {
        formObject.run($(this));
    });
});
  • 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-18T14:20:31+00:00Added an answer on June 18, 2026 at 2:20 pm

    Your issue is the use of the jQuery next function,

    Given a jQuery object that represents a set of DOM elements, the .next() method allows us to search through the immediately following sibling of these elements in the DOM tree and construct a new jQuery object from the matching elements.

    Your select box is not in the same set, so the next is returning an undefined and nothing is getting updated. If you just need to use this code once for this specific spot, you can add another class or id to your second selector to specify it.

    var formObject = {
     run : function(obj) {
        if (obj.val() === '') {
            obj.nextAll('.update').html('<option value="">----</option>').attr('disabled', true);
        } else {
            var id = obj.attr('id');
            var v = obj.val();
            jQuery.getJSON(SITE +'users/update_list', { id : id, value : v }, function(data) {
                if(!data.error) {
                    $('#secondSelect').html(data.list).removeAttr('disabled');
                } else {
                    $('#secondSelect').html('<option value="">----</option>').attr('disabled', true);
                }
            });
        }
    }  };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make will_paginate's :order to work with this array: @posts = current_user.subscribed_tags.map(&:posts).flatten.paginate(:page
I want to make a HTTP-request using node.js to load some text from a
I know I have done this in Javascript once, but how can I make
i want to create a virtual monitor. The way this would work is that
Unfortunately, SQL Server can not a handle a parameter list which exceeds 2100 parameters.
Are there browser related limits to the size of a text that can be
I would like to set some limits/boundaries on the amount of pixels we can
I have a problem when I try to extract from table (modele) all data
My application has to deal with large amounts of data, usual select size is
I have no idea why this isn't working. I've taken code from a previous

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.