Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:02:47+00:00 2026-06-13T15:02:47+00:00

I have my code that displays 92 selectors and each selector has a canvas(where

  • 0

I have my code that displays 92 selectors and each selector has a canvas(where is set a background color depending on the value from selector), in Jquery I set backgorund colors to canvas for the each value form selector, my problem is that when I click other selector it sets the backround color to the first Canvas(form the first selector but not on his own Canvas), I have 92 selector and each have CANVAS, how can I manage to do this in JQUERY…

Code

 <html>
   <head>
    <title>Tests</title>
    <style type="text/css">
     .table-container {
     display: inline-table;
     }
   table {
    width: 230px;
   }
  </style>
  <script src="js/jquery.js" type="text/javascript"></script>
  <script type="text/javascript">      
 $(document).ready(function(){
  $('select').change(function() {
   var selected = $(this).find(':selected').val();
    if (selected == 'Forms') {
     $('#myCanvas').css('background','green');
    }
      if (selected == 'language Syntax') {
     $('#myCanvas').css('background','yellow');
     }
      if (selected == 'Fundamentals') {
     $('#myCanvas').css('background','red');
     }
      if (selected == 'Advanced Concepts') {
     $('#myCanvas').css('background','blue');
     }
      if (selected == 'New Concepts in PHP5') {
     $('#myCanvas').css('background','violet');
     } 
     if (selected == 'Operators and Functions') {
     $('#myCanvas').css('background','black');
     } 
     if (selected == 'Variables and Datatypes') {
     $('#myCanvas').css('background','brown');
     } 
     });
  });
   </script>
     </head>
    <body>
   <h3>Tests</h3>
  <div class="table-container">
 <table border="3">      
   <tr>
       <th>
 <?php
  $con = mysql_connect("localhost","root","sergios.com");
 if (!$con)
 {
 die('Could not connect: ' . mysql_error());
  }

 mysql_select_db("phptests", $con);


$result1 = mysql_query("SELECT * FROM question");

for($i=1;$i<93;++$i)
 { 
  $result = mysql_query("SELECT * FROM Category"); 
 echo "Number:".$i."<br />";
 echo "<select>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
  echo "<option>" .  $line['name'] . "</option>";
}
echo "</select>"; 
?>
 <canvas id="myCanvas" width="20" height="20" style="border:1px solid #c3c3c3;">
   </canvas>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:02:48+00:00Added an answer on June 13, 2026 at 3:02 pm

    From what I observed, you are changing the same canvas element’s color (id=”myCanvas” => ‘#myCanvas’). Therefore, you need a way to uniquely associate each unique selector with each unique canvas.

    There are more elegant ways of recoding what you have coded. Due to the constraint of time, here is a sample by utilizing html element class names.

    // in php //////////
    <?php
    for($i=1;$i<93;++$i){ 
        $result = mysql_query("SELECT * FROM Category"); 
    ?>
        <br />
        Number: <?php echo $i; ?>
        <select class="<?php echo 'myCanvas_' . $i; ?>">
        <?php
        while($line = mysql_fetch_assoc($result)){
        ?>
            <option value="<?php echo $line['name']; ?>"><?php echo $line['name']; ?></option>
        <?php
        }
        ?>
        </select>
        <canvas id="<?php echo 'myCanvas_' . $i; ?>" width="20" height="20" style="border:1px solid #c3c3c3;"></canvas>
    <?php
    }
    ?>
    
    
    $(document).ready(function(){
        $('select').change(function() {
    
            var toChangeCanvasId = '#' + $(this).attr('class');
            var selected = $(this).find(':selected').val();
            if (selected == 'Forms') {
                $(toChangeCanvasId).css('background','green');
            }
            if (selected == 'Fundamentals') {
                $(toChangeCanvasId).css('background','red');
            }
    
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that reloads images via HTTP from the main thread and displays
I have found this line of MatLab code on the internet that displays a
I have code that sends web requests through two parallel for each loops. Will
I have created a grid view that displays six cells of content. In each
I have a usercontrol that has a popup that displays another usercontrol when the
I have a table that has a column that contains links. Each cell in
I have a code block that leads to a Internet Explorer cannot display the
I'have written a simple code, that gets accelerometer&orientation meter and display some graphics based
I have code that generates a List<string[]> variable but can't quite figure out how
I have code that looks more or less like the code below but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.