textarea problem when sending content to javascript function

N

Nate12o6

Mabee you guys can help me with this.
I have a form with enctype="multipart/form-data" that has a textarea in
it as well as file upload. The text area is for a description of the
file.

If someone uses the enter key to make 2 lines in the text area when it
is submitted it is stored in mysql database with (i guess) a line break
\n? When i pull the data out of mysql to put back into the textarea i
use the javascript function setup_update_form('<?=$docrow[0]?>',
'<?=$docrow[2]?>', '<?=$docrow[3])?>'"> and when this renders to html
it put a new line in the call variable and makes it look something like
this:

setup_update_form('18', '20', 'This is the first line
and this is the second')

Obviously javascript doesnt like this. I have also tried
setup_update_form('<?=$docrow[0]?>', '<?=$docrow[2]?>',
'<?=str_replace("\n", "", $docrow[3])?>')"> but it does absolutely
nothing difrent.
I have also tried nl2br() but all that does it add a <br> and keep the
newline.

Any help is apreciated.
 
C

Chad.Burggraf

Obviously javascript doesnt like this. I have also tried
setup_update_form('<?=$docrow[0]?>', '<?=$docrow[2]?>',
'<?=str_replace("\n", "", $docrow[3])?>')"> but it does absolutely
nothing difrent.
I have also tried nl2br() but all that does it add a <br> and keep the
newline.

You're on the right track. I'm not sure what server-side language
you're using (PHP?), but the newline character is just that - a
character. You should use a character replace function or a regular
expression to replace newlines in a string.

Cheers
Chad
 
N

Nate12o6

Wrap is not being defined, the newline is comeing from the user input
into the textarea.
Is there a PHP function that will give me every ascii value from a
string so i can figure out what that newline char is?

Thanks for the help!
Mabee you guys can help me with this.
I have a form with enctype="multipart/form-data" that has a textarea in
it as well as file upload. The text area is for a description of the
file.

If someone uses the enter key to make 2 lines in the text area when it
is submitted it is stored in mysql database with (i guess) a line break
\n? When i pull the data out of mysql to put back into the textarea i
use the javascript function setup_update_form('<?=$docrow[0]?>',
'<?=$docrow[2]?>', '<?=$docrow[3])?>'"> and when this renders to html
it put a new line in the call variable and makes it look something like
this:

setup_update_form('18', '20', 'This is the first line
and this is the second')

Obviously javascript doesnt like this. I have also tried
setup_update_form('<?=$docrow[0]?>', '<?=$docrow[2]?>',
'<?=str_replace("\n", "", $docrow[3])?>')"> but it does absolutely
nothing difrent.
I have also tried nl2br() but all that does it add a <br> and keep the
newline.

Any help is apreciated.

You're almost there. Replacing the character that causes the newline is
the right approach. However, first you need to figure out just what that
character is.

First of all, how is your textarea defined? Are you using the
(unofficial) attribue wrap = hard | soft | off ? (If set to hard, try
setting to soft. If not, forget about it.)

Second, where is the newline character being added to the textstring?
PHP? The database? Can you change that behavior?

Third, if you're stuck with the character arriving in the textstring,
you'll need to figure out exactly which character it is. Write a test
page, using PHP and the database to write the string directly to the web
page, no JS involved. Examine the page source to find the character and
figure out its ASCII value. THEN you'll know exactly which character to
replace using JS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top