While browsing through similar questions, I noticed that my query has a unique twist. I am working on a timesheet web app where employees submit their time in a table, which is then sent to H.R. in readonly mode. H.R. can approve or reject the timesheet based on specific criteria. To make it easier for H.R. Reps to identify incorrect entries, I came up with the idea of allowing them to click on cells and turn them red if needed. This way, when the timesheet is rejected and returned to the employee, they can easily see what needs correction.
I have written a small snippet in Javascript:
var validTextArray = {};
var backgroundColorArray = {};
function clearTextBox(textBoxID)
{
if (document.getElementById(textBoxID).value != "#ERROR")
{
backgroundColorArray[textBoxID] = document.getElementById(textBoxID).style.backgroundColor;
validTextArray[textBoxID] = document.getElementById(textBoxID).value;
document.getElementById(textBoxID).value = "#ERROR";
document.getElementById(textBoxID).style.backgroundColor = "red";
}
else if (validTextArray[textBoxID] != null)
{
document.getElementById(textBoxID).value = validTextArray[textBoxID];
document.getElementById(textBoxID).style.backgroundColor = backgroundColorArray[textBoxID];
}
}
To make sense of my c# script, here's a snippet:
day1PH.Attributes["onclick"] = "clearTextBox(this.id)";
day1PN.Attributes["onclick"] = "clearTextBox(this.id)";
day1LV.Attributes["onclick"] = "clearTextBox(this.id)";
day1TL.Attributes["onclick"] = "clearTextBox(this.id)";
day2PH.Attributes["onclick"] = "clearTextBox(this.id)";
day2PN.Attributes["onclick"] = "clearTextBox(this.id)";
day2LV.Attributes["onclick"] = "clearTextBox(this.id)";
//etc...
The functionality works perfectly, but I am facing an issue capturing those errors. When H.R. rejects the timesheet, all data is rewritten to an SQL Database. However, as the text was set by Javascript using "#ERROR" values, they do not get transferred over.
How can I capture these values effectively?