php - using JQuery with mySQL confusion -


Hello, I have code like this, what I'm doing is first selects with MySQL data and the first selection Based on, using jQuery, I'm populating the second one. Now, my question is, can I use the same combos_get.php to populate the second selection based on user selection from the second selection?

If yes, then please see the 'Traps at this point' comment, where I am confused about getting the data on the third selection.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Link href = "style23.css" rel = "stylesheet" type = "text / css" /> & Lt; Script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div align = "left" style = "position: full; top: 10px;" & Gt; & Lt; Select name = "selection1" id = "selection1" size = "10px;" & Gt; & Lt ;? Php // MySQL connection mysql_connect ("localhost", "root", "bob") or die (mysql_error ()); Mysql_select_db ("mydb") or die (mysql_error ()); $ Result = mysql_query ("Select * from the results where the id does not like"% EX ") or die (mysql_error ()); // Enter the" example "table in the record $ line ($ row = mysql_fetch_array ( $ Result)) {// Print the contents of the entry? & Gt; & lt; option value = "& lt ;? Php echo $ row ['id'] ;? & Gt; "& gt; & lt ;? Php echo $ line ['id']? & Gt;  
Php}? & Gt; & lt; / select & gt; & Lt; br & gt; script type = "text / javascript" & gt; $ (document) .ready (function () {$ ('# select1') .changes (getDropdownOptions); // $ (' # Select2 ') .changes (getDropdownOptions); // stuck at this point}); function getDropdownOptions () {var val = $ (this) .val (); // Warning (val); // combos_get.php $ Burning a post request for .post ('combos_get.php', {value: val}, populated dropdown, 'html'); // Warning ('s');} function populateDropdown (data) {if (data! = 'Error {$ ('# Select2') .HTML (data);}}
select name =" selection2 "size =" 10px; "id =" select2 ">

You want more than one handler for this matter. This is for you whether the same PHP file query Whether or not it can handle:

  $ (document) .ready (function () {$ ('# select1'). $ ('# Select2'). Changes (getSecondDropdownOptions);}); Function getSecondDropdownOptions () {var val = $ (this) .val (); $ .post ('combos_get.php', {value: val}, populated secondary dropdown, 'html'); } Function populateSecondDropdown (data) {if (data! = 'Error') {$ ('# YOURNEXTSELECT'). Html (data); }}  

Common practice is to reuse the code as much as possible. I do not have time for a refactor because I have to work only, but for that there is more welcome than anyone to clean it.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -