0

I tried the instructions on the website on how to use it. But it doesn't work. Btw here are my codes:

**select3.php**

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="dynamic_table.js"></script>
    <script type="text/javascript" src="jquery.jCombo.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#category").jCombo("getCategory.php");

            $("#type").jCombo("getType.php?id_cat=",{parent:"#category"});

            $("#desc").jCombo("getDesc.php?id_subcate=",{parent:"#type"});

        });
        </script>


    </head>

    <body>

        <form>

            <input type="button" value="Add" onclick="addRow('tableID')" />

            <input type="button" value="Delete" onclick="deleteRow('tableID')" />

            <table id="tableID">

                <tr>
                    <td></td>
                    <td>Category</td>
                    <td>Sub Category</td>
                    <td>Product Description</td>
                </tr>

                <tr>
                    <td><input type="checkbox" name="chkbox[]" id="chkbox"/></td>
                    <td>
                    <select id="category" name="category[]" />
                    </select>
                    </td>

                    <td>
                    <select id="type" name="type[]" />
                    </select>
                    </td>

                    <td>
                    <select id="desc" name="desc[]" />
                    </select>
                    </td>
                </tr>

            </table>

        </form>

    </body>

</html>

**getCategory.php**

    <?php 

    include 'db_config.php';
    mysql_connect($host,$user,$password);
    mysql_select_db($db) OR die("can not select the database $db");


    $query = "SELECT `id_cat`, `name` FROM `categories`"; 
    $result = mysql_query($query); 
    $items = array(); 
    if($result && mysql_num_rows($result)>0) {
        while($row = mysql_fetch_array($result)) {
            $items[$row[0]] = $row[1];
        }        
    } 
    mysql_close(); 
    header('content-type: application/json; charset=utf-8');
    // convert into JSON format and print
    $response = json_encode($items);
    if(isset($_GET['callback'])) {
        echo $_GET['callback']."(".$response.")";  
    } else {
        echo $response;         
    }

?>

**getType.php**

    <?php 

    include 'db_config.php';
    mysql_connect($host,$user,$password);
    mysql_select_db($db) OR die("can not select the database $db");


    $query = "SELECT `id_cat`, `name` FROM `categories`"; 
    $result = mysql_query($query); 
    $items = array(); 
    if($result && mysql_num_rows($result)>0) {
        while($row = mysql_fetch_array($result)) {
            $items[$row[0]] = $row[1];
        }        
    } 
    mysql_close(); 
    header('content-type: application/json; charset=utf-8');
    // convert into JSON format and print
    $response = json_encode($items);
    if(isset($_GET['callback'])) {
        echo $_GET['callback']."(".$response.")";  
    } else {
        echo $response;         
    }

?>

**getDesc.php**

    <?php 

    include 'db_config.php';
    mysql_connect($host,$user,$password);
    mysql_select_db($db) OR die("can not select the database $db");


    // Get parameters from Array
    $typeid = !empty($_GET['id_subcate'])?intval($_GET['id_subcate']):0; 

    // if there is no city selected by GET, fetch all rows     
    $query = "SELECT `id_type`, `name` FROM `type` WHERE `id_subcate` = '$typeid'"; 



    //  fetch the results
    $result = mysql_query($query);
    $items = array();
    if($result && mysql_num_rows($result)>0) {
        while($row = mysql_fetch_array($result)) {
            $items[$row[0]] = $row[1];
        }        
    }
    mysql_close();  
    header('content-type: application/json; charset=utf-8');
    // convert into JSON format and print
    $response = json_encode($items);
    if(isset($_GET['callback'])) { //json padding
        echo $_GET['callback']."(".$response.")";  
    } else {
        echo $response;         
    }

?>

**dynamic_table.js**


            function addRow(tableID) {

            var table = document.getElementById(tableID);

            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

            var colCount = table.rows[0].cells.length;

            for(var i=0; i<colCount; i++) {

                var newcell = row.insertCell(i);

                newcell.innerHTML = table.rows[1].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch(newcell.childNodes[0].type) {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "checkbox":
                            newcell.childNodes[0].checked = false;
                            break;
                    case "select-one":
                            newcell.childNodes[0].selectedIndex = 0;
                            break;
                }
            }
        }

        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;

            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    if(rowCount <= 2) {
                        alert("Cannot delete all the rows.");
                        break;
                    }
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }


            }
            }catch(e) {
                alert(e);
            }
        }
2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by LastMitch
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.