<?php $kategorie = $pdo->prepare("SELECT kategorie FROM tdgm_kategorien");
$kategorie->execute(array()); ?>
<select name="rubrik" id="where" class="input">
<?php while($r = $kategorie->fetch()) {
$kat = $r['kategorie']; ?>
<optgroup label="<?= htmlspecialchars($r['kategorie'], ENT_COMPAT, 'UTF-8') ?>"
value="<?= htmlspecialchars($r['kategorie'], ENT_COMPAT, 'UTF-8') ?>">
<?php $rubrik = $pdo->prepare("SELECT rubrik FROM ".$r['kategorie']."");
$rubrik->execute(array());?>
<?php while($e = $rubrik->fetch()) { ?>
<option class="option" value="<?= htmlspecialchars($e['rubrik'], ENT_COMPAT, 'UTF-8') ?>">
<?= htmlspecialchars($e['rubrik'], ENT_COMPAT, 'UTF-8') ?> </option><?php } ?></optgroup><?php } ?>
</select>
How can I pass the corresponding value of an optgroup to a script according to the option chosen?
optgrouphas novalueattribute. But you can prepend theoptgroupvalue to theoptionseperated by something like::. Then on the server, you split the value by::to get both the$kategorieand the$rubrik.HTML
SERVER