Jump to content

line breaks not working


ProblemHelpPlease

Recommended Posts

I have a textarea field that has a series of number in it each on its own line(the new line made by pressing return). The data gets passed in a form back to the page which then processes it with php and explodes the content of the textarea based on a matching \r\n so that it creates an array of all the different number on each line. This works fine.I am now trying to add a new section that allows new number to be added to the textarea by clicking on a list of numbers elsewhere on the page. Clicking on one of the numbers makes it appear in the textarea. To do this I am using javascript and modifying the textarea by adding the number+"\r\n" to the innerhtml of the textarea.This works and adds the number in the textfield with a return after it but when the page tries to process the data with php the explode cannot find a match for \r\nAnyone any ideas whyIf I echo the passed data with <pre> tags to show the returns there arnt any yet in the textarea the data has returns and if I press return manually after an entry it works. The echo shows24234234 23423432432 2342343242 23423234instead of24234234\r\n23423432432\r\n2342343242\r\n23423234I think it may have something to do with javascript removing the returns or part of the returns when it returns the data to the page

Link to comment
Share on other sites

Remember that different systems create line breaks with different characters. Assuming it will always be \r\n could cause trouble. A simple regex could match all 3 possibilities. I'm pretty sure \r\n|\r|\n does the job.When adding a newline in JS, I only ever use the \n sequence. Seems to work fine everywhere.

Link to comment
Share on other sites

The regex didnt work as the returns were being lost and converted into spaces (still not sure why).Changing from use innerHTML to value in the JS seems to have maintained the returns rather than converting them so with a adjustment to the code it now works.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...