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 9171203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:07:52+00:00 2026-06-17T16:07:52+00:00

I am trying to highlight cells with user preferred colors. A user will select

  • 0

I am trying to highlight cells with user preferred colors. A user will select a cell and drag mouse to select multiple cells that they want to color with the selected color. How can I trigger the javascript function that lives in a separate file (i know I have to include the file to html file, I have done that already) when user click and drag the mouse without using inline event handlers.

The code is there to drag and select but I would like to call this function when user click and drag cells. Before I was using google.setOnLoadCallBack to call this function, but that would call it only once. I would like user to have multiple selections. I hope I made sense.

HTML

<section id="importance">
   <label class="green">Green</label>
   <input type="radio" name="importance" value="green">

   <label class="yellow">Yellow</label>
   <input type="radio" name="importance" value="yellow">

   <label class="orange">Orange</label>
   <input type="radio" name="importance" value="orange">

   <label class="red">Red</label>
   <input type="radio" name="importance" value="red">
</section>

<table cellpadding="0" cellspacing="0" id="our_table">
  <tr>
   <td>a</td>
   <td>b</td>
   <td>c</td>
  </tr>
  <tr>
    <td>d</td>
    <td>e</td>
    <td>f</td>
  </tr>
  <tr>
    <td>g</td>
    <td>h</td>
    <td>i</td>
  </tr>
</table>

Javascript

function select_multiple() {
  var isMouseDown = false;
  // id for all the cells that were selected at the same time
  var colorGroupId = Math.floor(Math.random() * 1000);
  var highlight = find_importance_color();
  $("#our_table td")
    .mousedown(function () {
      isMouseDown = true;
      $(this).toggleClass(highlight);
      $(this).attr("data-highlightedId", colorGroupId);
      return false; // prevent text selection
  })
  .mouseover(function () {
    if (isMouseDown) {
      $(this).addClass(highlight);
    }
  });

  $("#our_table td")
    .mouseup(function (event) {
    isMouseDown = false;
    // time_importance(event);
  });
}

function find_importance_color() {
    return $('#importance input[name=importance]:checked').val();
}

CSS

.green {
  background-color: green;
}

.yellow {
  background-color: yellow;
}

.orange {
  background-color: orange;
}

.red {
  background-color: red;
}

table td {
  width:100px;
  height:100px;
  text-align:center;
  vertical-align:middle;
  background-color:#ccc;
  border:1px solid #fff;
}
  • 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-17T16:07:52+00:00Added an answer on June 17, 2026 at 4:07 pm

    Pass your initialization function to the jQuery ready handler:

    $(document).ready(select_multiple);
    

    jQuery will then call it when the document is loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write some code that will look in an excel cell
I'm trying to highlight the table cell that is in row, col. var $tr
I'm trying to find a Java library to highlight code. I don't want to
I'm trying to write a Google chrome extension so that I can highlight text
I'm trying to save information about text that a user has highlighted in a
Hi I'm trying to have my uitableviewcell rendered inactive so that a user can't
I wanted to color highlight cells that are different from each other; in this
I'm trying to setup a CSS style to highlight a table cell in a
I am trying to figure out how to have a table cell highlight when
I'm trying to set a Table View Cell that has been grouped, as a

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.