...

View Full Version : What is the best way to forward Textarea data?



Nitro2
03-21-2004, 05:29 PM
What is the best/simplest way to forward textarea data so that if on page1.html there is a textarea with new data entered in the following format:
======
Pencil
Pen
======

when submit is clicked, the data should be sent to a textarea on page2.html

I know how to do this with input areas where data has to be in one line, but with the textarea i want the data to be on seperate links, one under the other - not everything forced into one line.

What is the best/simplest way to implement this?

Thanks

Antoniohawk
03-21-2004, 11:02 PM
How did you do it with input fields? Sounds to me like this is more of a server-side questions since javascript can't read/write to a file without IE activeX, which is what you would need to do if you were to accomplish this with javascript.

Nitro2
03-21-2004, 11:20 PM
This is what i used:

page1.html


<html>
<body>
<form method="GET" action="page2.html">
<input type=text name=myvar>
<input type=submit value="submit">
</form>
</body>
</html>


page2.html


<html>
<body>
<script>
startat = window.location.search.length
myvar=window.location.search.substring(7,startat);
</script>

<form name="whatever">
<input type="text" name="newvar" value=myvar>
</form>
</body>

<script>
document.forms["whatever"].newvar.value = myvar;
</script>
</html>
</body>
</html>


Another question, is there a way to force a textarea box to interpret a "\n" as being a breakline as opposed to treating it as normal text?

Antoniohawk
03-21-2004, 11:30 PM
This question does in fact belong in the php section of these forums. Hopefully a mod will see this and be nice enough to move it for you.

Nitro2
03-21-2004, 11:39 PM
No, i want somehow to do this with javascript - i don't want php.

Anyone know whether there is a way to force a textarea box to interpret a "\n" as being a breakline as opposed to treating it as normal text?

glenngv
03-22-2004, 08:31 AM
You need to unescape the value parsed from URL to get its actual value. If you use textareas in your pages and use your existing code, the text will display newlines as newlines in the textarea.

<script>
document.forms["whatever"].newvar.value = unescape(myvar);
</script>

There is a better script (http://www.codingforums.com/showthread.php?s=&threadid=25786) that can parse multiple URL querystrings. Your existing code will only work if there is only one 5-letter parameter. In that script, you don't need to unescape the value as the script already does it for you.

Nitro2
03-22-2004, 02:59 PM
That works great :D
One other thing, the method i'm using, if i use two words and they have a space in between - once it gets sent to the textarea in the next page, the words end up having a "+" in between them because the address bar has a "+" in it. Is there anyway to replace "+" with a space instead?

Thanks

glenngv
03-23-2004, 01:49 AM
I think the script I linked handles that properly. Are you using that script?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum