Text in textarea chopped off after quote or apostrophe - Code-Tips.com - Web Development, Programming, SEO

Monday, September 13, 2010

Text in textarea chopped off after quote or apostrophe

I had an issue, where the text in a textarea input was being cut off after a quote or apostrophe.  The form was submitting to a ‘confirm’ mode, which displayed the details entered into the form back to the user for confirmation.  The details were being passed between each page/mode using hidden fields.  I found that if there was a quote or apostrophe in the text entered into the textarea field, it would be chopped of once the data had been submitted, or if pressing the ‘modify’ button on the confirm page.  After having a look at the page source of the confirm page, I noticed that the value from the textarea field which was being stored in a hidden variable spanned across multiple lines in the code.  As the value of the hidden text field was wrapped in quotation marks, the result was that the parser would stop think that the textarea content had finished.  As the content spanned across multiple lines, the parser would resume rendering the page content even though it was still within the text inside the hidden field value.

I tried a few things with limited success, including removing all line breaks from the text so that is it rendered on one line as well as encoding the quotation marks when including as an attribute value, but the solution I used was to store the value from the textarea field in a hidden textarea field on the confirm page instead of a hidden input field type.  I used the display attribute (display: none) to hide the text area from being displayed on the page.


Post a Comment