我有两个选择项:“代理”和“代码”。我想让“代码”选择项中的选定选项在我们更改“代理”选择项中的选定索引时更改,以便在选择中显示正确“代理”的正确“代码”项目。这是我到目前为止所做的,但它似乎不起作用:
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=bp', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
<script>
var agence = document.getElementById('agence');
var code = document.getElementById('code');
agence.addEventListener('change', function() {
code.selectedIndex = agence.selectedIndex;
}, false);
</script>
<label for="agence">Agence</label><select name="agence" id="agence"><?php $age = $bdd->query('SELECT * FROM agences ;') or die(print_r($bdd->errorInfo())); ?><?php while($ddonnees2 = $age->fetch()){?><option value="<?php echo $ddonnees2['Agence'];?>"><?php echo $ddonnees2['Agence'];?></option><?php } ?></select>
<label for="code">code</label><select name="code" id="code"><?php $age = $bdd->query('SELECT * FROM agences ;') or die(print_r($bdd->errorInfo())); ?><?php while($ddonnees2 = $age->fetch()){?><option value="<?php echo $ddonnees2['Code'];?>"><?php echo $ddonnees2['Code'];?></option><?php } ?></select>