Select option using PHP loop
P粉788765679
P粉788765679 2024-02-26 21:29:03
0
1
339

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>';
}

P粉788765679
P粉788765679

reply all(1)
P粉105971514

Your problem is in the Javascript code.

Remove the script from the while loop and place it at the end before the

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!