Click to See Complete Forum and Search --> : Textarea - escape line breaks


KingB
11-06-2003, 04:54 PM
Hi - I'm trying to use a textarea in a form. I want to replace each line break with &ph%5B%5D= , but it's not escape-ing properly it shows in the address bar as %26ph%5B%5D%3D

I think I'm 90% there... here's my code

<SCRIPT LANGUAGE="JavaScript">
function escapeVal(textarea,variable2){
variable = "&ph%5B%5D=";
variable2 = unescape(variable);
textarea.value = escape(textarea.value)
for(i=0; i<textarea.value.length; i++){
if(textarea.value.indexOf("%0D%0A") > -1){
textarea.value=textarea.value.replace("%0D%0A",variable2)
}
else if(textarea.value.indexOf("%0A") > -1){
textarea.value=textarea.value.replace("%0A",variable2)
}
else if(textarea.value.indexOf("%0D") > -1){
textarea.value=textarea.value.replace("%0D",variable2)
}
}
textarea.value=unescape(textarea.value)
}
</script>


<input type="submit" onclick="escapeVal(textarea,value)" value="Submit">

Any ideas? Thanks in advance!

AdamGundry
11-07-2003, 02:14 AM
The amp (&) and equals sign are special characters in URLs, which is why they are being automatically escaped. You will probably need to either use different characters or unescape them at the other end.

Adam

KingB
11-07-2003, 08:51 AM
AG - I kind of need those characters cuz the sql query depends on it. On the returning page the text displays properly, however in the url it's encoded. I believe that it needs to be unescaped before sending... here's a url sample:

http://64.65.203.147/intranet/dnc/dnc_master.php?ph%5B%5D=2224864%26ph%5B%5D%3D2224888%26ph%5B%5D%3D

It seems that the only problem I'm having is with the "&" and "=". How can I (re)write it in the script that these are passed 'cleanly'

AdamGundry
11-07-2003, 09:13 AM
Those characters must be escaped before sending, because they have special meaning in URIs (to do with passing parameters via GET queries). You might be able to use a POST query instead (so data is passed in a form, not on the URL), otherwise you will need to unescape them at the other end, in the code that does the SQL query.

Adam

KingB
11-07-2003, 10:03 PM
Hmmm - Been looking at trying to reassemble on the target side, no luck.

Maybe a new angle is needed. Basically all I'm trying to do is use a single textarea that sends each line as seperate variable in an array. However this array must be in the url as the form needs to use GET. For example see: http://64.65.203.147/intranet/dnc/dnc_search.php

Any ideas?