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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:10:30+00:00 2026-05-22T20:10:30+00:00

I want to generate some data for editing, filtered by the choice a user

  • 0

I want to generate some data for editing, filtered by the choice a user makes in a dropdown menu, but I don’t want to complicate things.

I already have my project querying the database for a list of “trees”, and populating a dropbox with the tree name, assigning the tree_id as its value.

All I want to do is, when the user makes a choice in the drop-down, have JQuery return a list of only that ID’s relevant data (description, etc).

What’s the simplest way to do that? Do I even need to make an AJAX request? Here’s my code:

CONTROLLER:

$this->load->model('Model_form','', TRUE);
$data['trees'] = $this->Model_form->get_tree();
$this->load->view('view_form_tree', $data);

MODEL:

function get_tree(){
$query = $this->db->query('SELECT * FROM trees');
return $query->result();
}

VIEW:

<h1>Edit Tree</h1>
<select id="f_treeindex" name="f_treeindex" class="dd_black">
<option value=""></option>
<?php
foreach($trees as $tree){
    echo '<option value="' . $tree->id . '">' . $tree->tree_name . '</option>';
}
?>
</select>

<script type="text/javascript">
     $(document).ready(function() {
        $('#f_treeindex').change(function(){
            var tree_id = $('#f_treeindex').val();
            if (tree_id != ""){
                //DO WHATEVER I NEED TO DO TO CALL THE INFORMATION FOR THE TREE WHOSE ID MATCHES THAT SELECTED IN THE DROPDOWN
            }//end if
        }); //end change
     }); //end docready
</script>

Just a note that the SELECT * statement in the model will return the tree_id, tree_name, and tree_description.

  • 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-22T20:10:30+00:00Added an answer on May 22, 2026 at 8:10 pm

    If you make a ‘show’ controller method that returns a bare template with the data (ie: not with the full layout), you can do something like this:

    $('#f_treeindex').change(function(){
        var tree_id = $('#f_treeindex').val();
        if (tree_id != ""){
            $.get('/controller_name/show', {id:tree_id}, function(data){
                $(this).parents('div').append(data);
            })
        }//end if
    });
    

    Wrap the <select> in a <div> so your jquery has something to append the resulting html to.

    Also, I would rename get_tree() to get_trees(), that way you can also do a get_tree($id) that returns a single tree in your controller_name#show method, which you can have return a template without the layout, to be appended.

    function show() {
        $this->load->model('Model_form','', TRUE);
        $data['tree'] = $this->Model_form->get_tree($this->params['id']);
        $this->load->view('single_tree_view', $data);
    }
    

    also, not 100% sure how your CI is set up, so your $.get line might need to be

    $.get('/controller_name/show/'+tree_id, function(data){...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate some formatted output of data retrieved from an MS-Access database
I want to generate some XML in a stored procedure based on data in
I want to auto-generate a HTML table from some custom data. One of the
What I'm trying to accomplish My app generates some tabular data I want the
Using T4 I want to generate some code based on examining what files are
I have a task and I want to generate some code using the CodeDom.
I need to generate some passwords, I want to avoid characters that can be
I want to make some variables I generate in b available in c: a
I'm looking for a free templating engine to generate simple reports. I want some
I want to generate a thumbnail preview of videos in Java. I'm mostly JMF

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.