Note that there are some explanatory texts on larger screens.

plurals
  1. POCode Igniter php - return (ajax?) data based on dropdown selection with JQuery
    primarykey
    data
    text
    <p>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. </p> <p>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.</p> <p>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). </p> <p>What's the simplest way to do that? Do I even need to make an AJAX request? Here's my code:</p> <p>CONTROLLER:</p> <pre><code>$this-&gt;load-&gt;model('Model_form','', TRUE); $data['trees'] = $this-&gt;Model_form-&gt;get_tree(); $this-&gt;load-&gt;view('view_form_tree', $data); </code></pre> <p>MODEL:</p> <pre><code>function get_tree(){ $query = $this-&gt;db-&gt;query('SELECT * FROM trees'); return $query-&gt;result(); } </code></pre> <p>VIEW:</p> <pre><code>&lt;h1&gt;Edit Tree&lt;/h1&gt; &lt;select id="f_treeindex" name="f_treeindex" class="dd_black"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;?php foreach($trees as $tree){ echo '&lt;option value="' . $tree-&gt;id . '"&gt;' . $tree-&gt;tree_name . '&lt;/option&gt;'; } ?&gt; &lt;/select&gt; &lt;script type="text/javascript"&gt; $(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 &lt;/script&gt; </code></pre> <p>Just a note that the SELECT * statement in the model will return the tree_id, tree_name, and tree_description.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload