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 pletely 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!
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 pletely 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!
Share Improve this question edited Sep 28, 2012 at 9:19 Blanca Hdez asked Sep 28, 2012 at 7:59 Blanca HdezBlanca Hdez 3,56319 gold badges72 silver badges95 bronze badges 2- toLoad != setAttachmentToLoad – Barmar Commented Sep 28, 2012 at 8:15
- That was a typing error when I wrote the question. In my code it has the same name – Blanca Hdez Commented Sep 28, 2012 at 8:18
3 Answers
Reset to default 3The \
is an escape character and therefore needs to be duplicated to bee a literal \
, that is, substitute all \
symbols with \\
and retry.
See Javascript - Replacing the escape character in a string literal
\
is reserved as an escape character in Javascript for special characters.
http://www.javascriptkit./jsref/escapesequence.shtml
Escaping \
itself happens with two \\
Use escape and unescape functions The unescape() function decodes an encoded string. http://www.w3schools./jsref/jsref_unescape.asp