Hello,

I want to get checkbox depending on choice dropdown list.
this is my code

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"  media="all" charset="utf-8"/>
    <title>APPLICATION</title>


    <script type="text/javascript">
  function changerub(rubrique){
    var divIds= new array('agent');
    for(var i=0; i<divIds.length;i++){
      document.getElementById(divIds[i]).style.display = (i==rubrique)?'block':'none';
    }
  }
</script>
</head>

<body>

<?php
    $cnx=mysql_connect('localhost','root','') or die ("Erreur de connexion");
    mysql_select_db('saher',$cnx);

?>

<form method="post" action="" id="form_1" >
<table border=0 align=center width="100%" cellpadding='3' cellspacing='2'>
<tr>
<th colspan=4>FILTER</th>
</tr>
<tr>
<th>Sensor</th>
<td>
    <div id="agent" style="display:none">
        <?php
            $sig_name=mysql_query("SELECT DISTINCT abreviation,adresse FROM agent");
            $rows=mysql_num_rows($sig_name);
            $cols=mysql_num_fields($sig_name);

    for ($i=0;$i<$rows;$i++)
    {   
            echo '<input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.mysql_result($sig_name,$i,0).'">';
            echo mysql_result($sig_name,$i,0);
    }


    ?>
</div>
</td>

<th>ISP</th>
<td >
<select name="isp" value="isp" onChange="changerub(form_1.isp.selectedIndex);">
    <option value="0" selected="selected" >ALL</option>
    <?php
    $isp_name=mysql_query("SELECT DISTINCT nom_fsi FROM fsi order by nom_fsi asc");
    while($data=mysql_fetch_array($isp_name))
    {
        echo "<option>".$data["nom_fsi"]."</option>";
    }
    ?>
</select>
</td>
</tr>
<tr>
    <td colspan=4>
        <input type="submit" value="Valider" name="filter"  />   
        <input type="submit" value="Generate report" name="report" onClick="openReport('form_1','tcpdf/report2.php')">
    </td>    
</tr>
</table>
</form>
<center>
</body>
</html>
Member Avatar for diafol

Please explain in detail what you wish to achieve. You have javascript, php. sql queries and html all jumbled up. Very difficult to follow.

Separating your php from markup and placing js into listeners is good for producing clean code.

i want to get checkbox from depending on dropdown choice

Member Avatar for diafol

That's just repeating your original request.

Because your code is jumbled up all over the place, contributors will need to sift through it and try to make some sense of it. That's not really fair. If you explain in detail what a select field is passing, how it is then supposed to retrieve data (from a DB?) and then what's supposed to happen.

You may find this post helpful:

https://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.