I have the code below which works but only after clicking to select the option but when I change the value while using the up and down arrows the code does not work.
I tried modifying the script to change the option "Click" to "Change" but this solution did not work. Can anyone help me?
$select = $db_connect -> query("SELECT * FROM templates"); if($select -> num_rows > 0) { echo '<select id="subject" name="subject" class="form-select">'; while($row = $select -> fetch_assoc()) { echo '<option id="'.$row["id"].'" value="'.$row['template_subject'].'">'.$row['template_subject'].'< /option>'; ?> <script> $("#subject #<?php echo $row['id']; ?>").on('click', function(){ if((this.id = "<?php echo $row['id'];?>") && (this.id != 1)) { $("textarea").html("<?php echo $row['template_text']; ?>"); $("input[name='new_subject']").hide(); } else { $("textarea").html(""); $("input[name='new_subject']").show(); } }); </script> <?php } echo '</select>'; }
Your problem is in the Javascript code.
Remove the script from the while loop and place it at the end before the