I am sending a form with a notes field to an Oracle database and then displaying the notes. New notes can be added, and they will be appended to the previous note.
The problem I have is with the newline that I am inserting at the beginning of each notes update. I am sending notes updates to the database with a javascript in this manner: oldNote + "\n" + date + " " + username + ": " + newNote;.
This is the php part:
echo "<input class='button' type='button' id='Save' name='saveInteraction' onclick=\"saveInteractionInfo('$oldNote', '$date', '$username', '$interactionId', '$seqNum');\" value='Update'/>";
This is the entire javascript function:
function saveInteractionInfo(oldNote, date, username, interactionId, seqNum) {
var formData = {};
formData['interactionId'] = interactionId;
formData['seqNum'] = seqNum;
formData['notes'] = oldNote + "\n" + date + " " + username + ": " + document.all.notes.value;
trxId = readCookie("transactionId");
if(trxId)
formData["transactionId"] = trxId;
var respFunc = function(par1,par2,par3,par4) { postUpdateInteractionNotesResponseHandler(par1,par2,par3,par4); };
var errorFunc = function(reqId) { return showErrorCaseHandler(reqId); };
ajaxPostRequest("Interactions.php",formData,"Update Interaction Notes.","subExtra",respFunc,errorFunc);
}
Updating the notes works at it should, but when trying to update it for the second time I get an error in Firebug: unterminated string literal: saveInteractionInfo('Test, where saveInteractionInfo is the function I am passing the notes to and ‘Test’ is the form value. So the error occurs when the newline is passed to the function.
Any suggestions how I could get this working?
UPDATE So the problem is that the $oldNote has line breaks (\n) in it, which stops it from passing the data to the javascript function.
The tag now:
<input class='button' type='button' id='Save' name='saveInteraction' onclick="saveInteractionInfo('fdsfsfsf
dfdfdf
gdfgdg', '13/09/2011 16:11:13', 'blaha01', '7038245', '2');" value='Update'/>
The tag as it should be:
<input class='button' type='button' id='Save' name='saveInteraction' onclick="saveInteractionInfo('fdsfsfsfdfdfdfgdfgdg', '13/09/2011 16:11:13', 'blaha01', '7038245', '2');" value='Update'/>
Any other suggestions?
The solution was similar to the one posted by Rob W: