Hi this function is to add a Note to the database. Now I want to remove the Note when there is no text available in the Note.
I am unable to delete the row from the database and so the next time when the page loads the Note reappears. Kindly help me in the regard. Please let me know if I am doing something wrong.. As i am new to this..
function AddNote()
{
SetAccoutChangedToTrue(); //to signify that we'll need to prompt the user to save
var NoteExistingText = document.getElementById("contextMenuAddNote_ExistingNote").value;
var NoteText = document.getElementById("contextMenuAddNote_Note").value;
var NoteDesc = ""; //document.getElementById("contextMenuAddNote_NoteDesciption").value;
var NoteAutoText = document.getElementById("contextMenuAddNote_AutoNote").innerHTML;
var AssociatedCellID = document.getElementById("AssociatedCellIDforNote").value;
var CurrentUserUID = document.getElementById("contextMenuAddNote_CurrentUserUID").value;
var NoteDBUID = document.getElementById("contextMenuAddNote_NoteDBUID").value;
//first - trying to delete the note icon when there is no text
var SpanElementContainingNote = document.getElementById(AssociatedCellID + "_Note");
if(NoteText == "" && NoteExistingText == "")
{
if (SpanElementContainingNote != null)
{
var ParentOfSpanElementContainingNote = SpanElementContainingNote.parentNode;
ParentOfSpanElementContainingNote.removeChild(SpanElementContainingNote);
// what else should i write here to delete this note permanently.
}
else
{
return false;
}
}
else
{
if (SpanElementContainingNote != null)
{
var ParentOfSpanElementContainingNote = SpanElementContainingNote.parentNode;
ParentOfSpanElementContainingNote.removeChild(SpanElementContainingNote);
}
//add a new Note element
var AssociatedCell = document.getElementById(AssociatedCellID);
var TDofAssociatedCell = AssociatedCell.parentElement;
var spanNode = document.createElement("SPAN");
spanNode.setAttribute("id", AssociatedCellID + "_Note");
//spanNode.setAttribute("onclick", "Javascript:showContextMenuUpdateNote('" + AssociatedCellID + "','0', '" + NoteText + "');")
spanNode.onclick = function() { showContextMenuUpdateNote(AssociatedCellID, NoteDBUID, NoteText, NoteExistingText, NoteAutoText); };
var iconNode = document.createElement("img");
iconNode.setAttribute("src", "App_Themes/Default/Image/note.gif");
iconNode.setAttribute("border", "0");
iconNode.setAttribute("alt", NoteText);
spanNode.appendChild(iconNode);
spanNode.innerHTML = spanNode.innerHTML + "</IMG>";
var noteNode = document.createElement("NOTE");
noteNode.setAttribute("AssociatedCellID", AssociatedCellID);
if (NoteExistingText != "")
noteNode.setAttribute("NoteExistingText", NoteExistingText); //xml parser doesn't like empty strings
if (NoteText != "")
noteNode.setAttribute("NoteText", NoteText);
if (NoteAutoText != "" && NoteAutoText != "AUTONOTE_BLANK")
noteNode.setAttribute("NoteAutoText", NoteAutoText);
noteNode.setAttribute("NoteUpdatedBy", CurrentUserUID);
//noteNode.setAttribute("NoteDesc", NoteDesc);
noteNode.setAttribute("NoteDBUID", NoteDBUID);
noteNode.innerHTML = noteNode.innerHTML + "</NOTE>";
spanNode.appendChild(noteNode);
//TDofAssociatedCell.appendChild(spanNode);
TDofAssociatedCell.insertBefore(spanNode, TDofAssociatedCell.childNodes[0]);
}
hideContextMenu("contextMenuAddNote");
}