0

Trying to make a Dynamic Dependent Select Box using jQuery and Ajax.

Everything is fine but I'm getting blank page inside <fieldset>

I noticed this happens when I load jquery api (tried different versions).

Sources:

Lists:

<div>
        <label>Diplome :</label>
        <select name="diplome" class="diplome">
            <option selected="selected" value="0">Choisir Diplome</option>
            <?php
            include('db.php');
            $sql=mysql_query("select * from diplome");
            while($row=mysql_fetch_array($sql))
            {
            echo '<option value="'.$row['id_diplome'].'">'.$row['libelle'].'</option>';
            } ?>
        </select>
        <br/>
        <br/>
        <label>Section :</label>
        <select name="section" class="section">
            <option selected="selected">Choisir section</option>
        </select>
    </div>

Scripts:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function()
    {
        $(".diplome").change(function()
        {
            var id=$(this).val();
            var id_String = 'id='+ id;

            $.ajax
            ({
                type: "POST",
                url: "action.php",
                data: id_String,
                cache: false,
                success: function(sectiondata)
                {
                    $(".section").html(sectiondata);
                } 
            });

        });
    });
</script>

Action:

<?php
$hostname = "localhost";
$user = "root";
$password = "";
$database = "sondage";
$bd = mysql_connect($hostname, $user, $password) 
or die("DB Connection Failed!");
mysql_select_db($database, $bd) or die("DB Connection Failed!");

if($_REQUEST['id'])
{
    $id=$_REQUEST['id'];
    if($id==0){echo "<option>Choisir Section</option>";}else{
    $sql=mysql_query("select * from section where id_diplome='$id'");
    while($row=mysql_fetch_array($sql))
    {
    echo '<option value="'.$row['id_section'].'">'.$row['libelle'].'</option>';
}
}
}
?>

Console Error:

Uncaught TypeError: $.backstretch is not a function
    at HTMLDocument.<anonymous> (scripts.js:7)
    at j (jquery-1.11.1.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-1.11.1.min.js:2)
    at Function.ready (jquery-1.11.1.min.js:2)
    at HTMLDocument.J (jquery-1.11.1.min.js:2)

If anyone has an idea hmu, thanks.

SimonCo
  • 11
  • 3
  • 1. **Don't** use the **deprecated and insecure** `mysql_*`-functions. They have been deprecated since PHP 5.5 (in 2013) and were completely removed in PHP 7. Use MySQLi or PDO instead. 2. **You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php)** and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries, which can be used if you use the above mentioned MySQLi or PDO. – M. Eriksson Feb 11 '17 at 14:42
  • You should check your error log for PHP-errors. Here you can find more about showing errors in PHP: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – M. Eriksson Feb 11 '17 at 14:44
  • You should also check the browsers console for ev. javascript errors. – M. Eriksson Feb 11 '17 at 14:46
  • You are not including a plugin file for `backstretch ` – charlietfl Feb 11 '17 at 14:51
  • Solved it. Thanks a lot Magnus. – SimonCo Feb 11 '17 at 15:08

0 Answers0