Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 24 buttons, in circle shapes, all are inside a form, whenever I click on any of them, it turns red using javascript DOM, now when I click Submit form, I want all the colored buttons to be stored into the SQL Table, in other words, storing every button in their background color, so I could retrieve them in their saved colors!
Thank you

What I have tried:

echo"<button type='button' id='spoolid_$splno' name='spool_$splno' style='border: 1px solid black; font-size: 24px; border-radius: 50%' onclick='funclk_$splno()' $enble_disable>$y</button>";
                    echo"<script>
                        function funclk_$splno(){
                            if(document.getElementById('spoolid_$splno').style.backgroundColor==''){
                                var msg=prompt('What do you need to do?\\nScreen Change, Type 1\\nScrew Cleaning, Type 2');
                                if(msg==1){
                                    for(var j=$splno; j<=$totspl; j+=$chgscrnfrq){
                                        if(document.getElementById('spoolid_'+j).style.backgroundColor!=='$clnscrwclr'){
                                            document.getElementById('spoolid_'+j).style.backgroundColor='$chgscrnclr'; }
                                    }

}

if($_POST[clngsve]){
           $x=$_POST['spool_1'];
           echo"<script>alert('$splno')</script>";
           //$sql_mccln = "INSERT INTO MC_Clng (Lot_no) VALUES ('$_POST[lot_no]')";
           //$query_mccln = mysqli_query($con, $sql_mccln);
        }
Posted
Updated 17-Mar-23 18:55pm

1 solution

When you want to save them, loop through the buttons, and pick up the colours. Check them each for redness, and convert that to a true / false value. That bool is what send to your PHP code for it to save in the DB.
Then when you restore them, your PHP can check the bool and set the redness appropriately.

Javascript doesn't have access to the DB, the server code does - so send it the appropriate data!
 
Share this answer
 
Comments
Member 14819235 13-Nov-23 17:22pm    
Thank you
OriginalGriff 14-Nov-23 2:28am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900