Note that there are some explanatory texts on larger screens.

plurals
  1. PODB generated list not working when created using jquery
    primarykey
    data
    text
    <p>I have a simple form that has a list (dropdown list generated from a DB), when a user makes a selection, the selection is printed on the screen. The problem I'm having is that if I use jquery to call the php funciton that generates the list when the page is loading, the list will not work, but if I add the code directly in the html it will work <br> <br> When the page loads the dropdown list is called like this:<pre> <code> $('#createDropDown').ready(function(){ id = $('#createDropDown').val();  // this calls a php function that creates a dropdown list from the DB // the dropdown's id = 'categoryList' xajax_addDropdownMenu(id);</p> <p>}); </code></pre></p> <p>the list is generated with the <strong>id = 'categoryList'</strong>, and it is appended correctly to the createDropDown DIV called "createDropDown". Up until now everything looks good! The problem comes when a selection is made on the newly created list (categoryList) another Jquery is called </p> <p>when a selection is made the following code should be called:<pre> <code> $('#categoryList').change(function() { bucket_id = $('#categoryList').val();  var selected = ""; // get selected value from the dropdown menu $("#categoryList option:selected").each(function () { selected += $(this).text() + " ===>"; }); // if we have a valid ID print it in the screen. if(bucket_id!= 0) { xajax_addCategory(selected); } }); </code></pre> <strong>xajax_addCategory(selected);</strong> prints the selected item on the screen. but is not working.</p> <p>NOTE: This works OK if I call the php function to generate the dropdown directly in the main.html file, so I know that the list is being generated with the correct ID and it works, but when I use Jquery to call the php method on load, it doesn't work... and I don't understand why.</p> <p>PS I'm a noob of Jquery so some insight would be very welcome!</p> <hr> <p>UPDATE:</p> <p>I tried creating a binding after the list is generated like this: </p> <pre><code> $('#createDropDown').ready(function() { id = $('#createDropDown').val(); xajax_addDropdownMenu(id); $("#categoryList0").bind('change',function() { console.log('The code goes here!!'); }); }); </code> </pre> <p>where <strong>categoryList0 is the ID</strong> of the new list. the class of the list is categoryList</p> <p>but I'm still stuck because it is still not getting into the function when there is a change...</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