I am trying to create a dependent drop down list, but after making my first selection it is populating. Each selection will receive data from the MySQL
database in order for the second drop down to select any option (other then a default "selection option" value) in order for the user to make a selection on the first drop down. After a lot of googling, it takes me a simple time
drop down list (I use > MySQL PHP
and )
here in a getter.php
and need_once
in a index.php
to create and output drop down list And echo
drop down for)
$ accountOptions = ""; $ Feature option = ""; $ Dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); If (! $ Dbc) {dead ("Connection failure:". Mysqli_connect_error ()); } /// ACCOUNTS ///// $ accountQuery = "SELECT account_id, from account_name account"; $ AccountData = mysqli_query ($ dbc, $ accountQuery); // Looping through data and displaying all accounts ($ aRow = mysqli_fetch_array ($ accountData)) {$ accountOptions. = "& Lt; option value = \" ". $ ARow ['account_id']." \ "& Gt;" . $ ARow ['account_name'] "& lt; / options & gt;"; } $ AccountDropDown = "& lt; Labels & gt; Account: & lt; / label & gt; & lt; br & gt; & lt; name select name = 'account' id = 'account' change = ' GetFacility (this.value) '& gt; & lt; option selected =' selected 'disable =' disabled 'value =' '& gt; Select account & lt; / options & gt; $ AccountOptions "& lt; / Select & gt; "; //// utilities ///// $ feature_download =" & lt; Label & gt; Feature: & lt; / Label & gt; & Lt; Br> Select name = 'feature' id = 'feature' & gt; & Lt; Option selected = selected 'disabled =' disabled 'value =' '& gt; Select feature & lt; / Option & gt; & Lt; / Select & gt; ";
JQuery / AJAX
function getFacility (val) {$ .ajax ({type:" POST " Url: "Getfacility.php", data: 'account_id =' + val, success: function (data) {$ ("#type") .html (data);}});}
getfacility.php
// db connection .. if (! ($ _ POST ["account_id"])) {$ AccountID = $ _POST ['Account_id']; $ Sql = "SELECT *, from the account.account_name facility" "Join the account in the INNER account. Account_id = facility.account_id "" WHERE facility.account_id = '"$ AccountID."' "$ Data = mysqli_query ($ dbc, $ sql); resonance" & lt; Option selected = 'selected' disabled = 'disabled' value = '' & gt; Select feature & lt; / Option & gt; "; while ($ FRow = mysqli_fetch_array ($ data)) {$ feature option. =" & Lt; Option value = \ "". $ FRO ['feature_id']. "\" & Gt; "$ FRO ['feature_name']" & lt; / Option & gt; ";} $ feature = dropdown =" & lt; Label & gt; Feature: & lt; / Label & gt; & Lt; Br> & Lt; Select name = 'feature' id = 'feature' & gt; & Lt; Option selected = 'selected' disabled = 'disabled' value = '' & gt; Select feature & lt; / Option & gt; ". $ Feature Option" & lt; / Select & gt; ";}
Right now, when I make a selection on my first drop, nothing else happens, where I am getting wrong?
No comments:
Post a Comment