How is it possible to get two values with document.getElementById?
I have this code, where I'm trying to get the kontypeID and kontypeTitel from a selectbox to be written to text fields:
<select id="select" name="select" onchange="run()"> <?php $virksomhedsID = $_SESSION['virkID']; $sql = "SELECT * FROM konkurrenceType ORDER BY konkurrenceType.kontypeID"; $result = mysql_query($sql) or die(mysql_error()); echo '<option value="Vælg type">Vælg type</option>'; while($rowSelect = mysql_fetch_assoc($result)) { $kontypeID = $rowSelect['kontypeID']; $kontypeTitel = $rowSelect['kontypeTitel']; echo '<option value="' . $kontypeID . '">' . $kontypeTitel . '</option>'; } ?> </select> <script> function run() { var select = document.getElementById("select"); document.getElementById("valgtID").value = valgtTitel.options[select.selectedIndex].innerHTML; document.getElementById("valgtTitel").value = valgtTitel.options[select.selectedIndex].innerHTML; } </script> <input type="text" name="valgtID" id="valgtID"/> <input type="text" name="valgtTitel" id="valgtTitel"/>
id?document.getElementByIdreturns only the first appearance. However, you could usedocument.querySelectorAll("#id")if you really needed them.