This code is a simple function call:
<input type="submit" name="_eventId_load" onclick="toLoad('2012\9\27\15\2012-09-27T15-05-59-512.00638.eml');" value="Load"/>
This is what I receive in the js function:
function toLoad(path) {
document.getElementById("emailPath").value = escapepath);
}
Via firebug, I see that the param path contains: 201292-09-27T15-05-59-512.00638.eml
And after the scape function: 20129%17%0D%812-09-27T15-05-59-512.00638.eml
The values are completely different. How could I work/edit te \ before I send it to the js function?
Thanks in advance.
EDIT
This is the solution:
<input id="filePath-${status.index}" type="hidden" value="${file.path}"/>
<input type="submit" onclick="toLoad('${status.index}'" value="Load"/>
These inputs are inside a form, each element is a file. I need ${status.index} to know which file I want to load. ${file.path} contains the path I want to replace.
function toLoad(index) {
var emailPath = document.getElementById("filePath-" + index).value.replace(/\\/g,"\\\\");
document.getElementById("emailPath").value = emailPath;
}
The correct input will be included in a div, so I can use it for the final functionallity.
Thanks for your answers!
The
\is an escape character and therefore needs to be duplicated to become a literal\, that is, substitute all\symbols with\\and retry.See Javascript – Replacing the escape character in a string literal