undefined undefined - 1 year ago 62
Javascript Question

How to get the date of the selected <td> in a calendar

I need an idea and maybe a solution to get the date from the

s which are selected by mouse.

Heres my code, to select (until now its only a function to change the class) the TD:

$(function () {
var isMouseDown = false,
$("#schichtplan td")
.mousedown(function () {
isMouseDown = true;
isHighlighted = $(this).hasClass("highlight");
return false; // prevent text selection
.mouseover(function () {
if (isMouseDown) {
$(this).toggleClass("highlight", isHighlighted);
.mouseup(function () {
isMouseDown = false;

A screenshot from the calendar:

This is, how the days are displayed:

echo "<td class=\"td kal_standard_tag\"> - </td>";

The "-" is displayed, because at this day is no entry for this user.

Maybe I could add something like this and read it out with jQuery?


My target: After selecting the days, the user has to use rightclick and a Dialog shows up where the user can add some informations and save it to a database.
But I dont know how to get the selected days... :(

Does anyone have an idea and maybe a solution for that?

Answer Source

The best practice to do such things is to add a data attribute. So you would add a timestamp or datestamp as you said. E.g.: <td data-timestamp="1231232131"> and then get it with jQuery in an event with $(this).data('timestamp').

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download