PHP/JS: Dynamic Dropboxes and echoing SELECTED value
<p>I am currently working with a dynamic dropdown menu(dependable select boxes). I am pulling the values straight from MySQL DB(if your curious here is how i have the <a href="http://webprolearner.ueuo.com/images/DB..jpg" rel="nofollow">DB SETUP</a>). I am able to get the values of each table and display them accordingly. The problem I am having is echoing the SELECTED value of each selct box. I have a created JS function that will request postfile.php which will then echo the SELECTED value of each box. I am not getting anything echoed. I have checked with firebug but nothing is being posted. </p>

<p>How can I make this work? or Am I approaching this wrong? or Is there a better way? <a href="http://webprolearner.ueuo.com/dropdown-menu/" rel="nofollow">EXAMPLE</a></p>

<p><strong>Working HTML/PHP</strong></p>

<pre><code>&lt;?php

include ('includes/dbConnect.php');

try {

    $pdo = get_database_connection();   

    $sql = "SELECT * 
            FROM `categories`
            WHERE `master_id` = 0";
    $statement = $pdo-&gt;query($sql);
    $list = $statement-&gt;fetchAll(PDO::FETCH_ASSOC);


} catch(PDOException $e) {
    echo 'There was a problem';
} 

?&gt;

    &lt;select name="main" id="main" size="7" class="update"&gt;
        &lt;option value=""&gt;Select one&lt;/option&gt;
        &lt;?php if (!empty($list)) { ?&gt;
        &lt;?php foreach($list as $row) { ?&gt;
        &lt;option value="&lt;?php echo $row['id']; ?&gt;"&gt;
            &lt;?php echo $row['name']; ?&gt;
        &lt;/option&gt;
        &lt;?php } ?&gt;
        &lt;?php } ?&gt;
    &lt;/select&gt;
    &lt;select name="subc1" id="subc1" size="7" class="update" disabled="disabled" hidden="hidden"&gt;
        &lt;option value=""&gt;----&lt;/option&gt;
    &lt;/select&gt;
    &lt;select name="subc2" id="subc2" size="7" class="update" disabled="disabled" hidden="hidden"&gt;
        &lt;option value=""&gt;----&lt;/option&gt;
    &lt;/select&gt;
    &lt;select name="subc3" id="subc3" size="7" class="update" disabled="disabled" hidden="hidden"&gt;
        &lt;option value=""&gt;----&lt;/option&gt;
    &lt;/select&gt;
</code></pre>

<p><strong>JS</strong>  </p>

<pre><code> &lt;script type="text/javascript"&gt;
        $(document).ready(function () {
            $('#main).change(function() {
                  if ($(this).val()!='
            ') {
                    $("#subc1").load("postfile.php",{main_id: $(this).val()});
                    //$("#subc1").removeAttr('
            disabled hidden ');
                  }
                });
                //code on change of sel_source
                $('#subc1 ').change(function() {
                  if ($(this).val()!='
            ') {
                    $("#subc2").load("postfile.php",{subc1_id: $(this).val()});
                    //$("#colour").removeAttr('
            disabled ');
                  }

                });

                $('#subc2 ').change(function() {
                  if ($(this).val()!='
            ') {
                    $("#subc3").load("postfile.php",{subc2_id: $(this).val()});
                    //$("#colour").removeAttr('
            disabled ');
                  }

                });
            });
    &lt;/script&gt;
</code></pre>

<p><strong>PHP- postfile.php</strong></p>

<pre><code> if(isset($_REQUEST['main_id']) &amp;&amp; !empty($_REQUEST['main_id'])) {

    try {
    include ('../includes/dbConnect.php');

        $pdo = get_database_connection();


        $sql = ("select * from `categories` where id='".$_REQUEST['main_id']."' ");
        $result = $con-&gt;prepare($sql); 
        $result-&gt;execute(); 
        $number_of_rows = $result-&gt;fetchColumn();
    }catch(PDOException $e) {
        echo 'There was a problem';
    } 

        if($number_of_rows &gt; 0) {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
            while($row = mysql_fetch_assoc($result)) {              
                    $output .= '&lt;option value="'.$row['id'].'"&gt;'.$row['name'].'&lt;/option&gt;';
            }
        } else {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
        }
        echo $output;
    } 

    if(isset($_REQUEST['subc1_id']) &amp;&amp; !empty($_REQUEST['subc1_id'])) {
        $result = mysql_query("select * from table where id='".$_REQUEST['subc1_id']."' ");
        if($number_of_rows &gt; 0) {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
            while($row = mysql_fetch_assoc($result)) {              
                    $output .= '&lt;option value="'.$row['id'].'"&gt;'.$row['name'].'&lt;/option&gt;';
            }
        } else {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
        }
        echo $output;
    } 

    if(isset($_REQUEST['subc2_id']) &amp;&amp; !empty($_REQUEST['subc2_id'])) {
        $result = mysql_query("select * from table where id='".$_REQUEST['subc2_id']."' ");
        if($number_of_rows &gt; 0) {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
            while($row = mysql_fetch_assoc($result)) {              
                    $output .= '&lt;option value="'.$row['id'].'"&gt;'.$row['name'].'&lt;/option&gt;';
            }
        } else {
            $output = '&lt;option value=""&gt;Select&lt;/option&gt;';
        }
        echo $output;
    } 
</code></pre>
