• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

If last char of textarea is \n, Safari 3.2.1 seems to think the textarea contains extra \n.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written a web page called a.html.

The top part of a.html has a textarea called "userInputArea".

The bottom part echoes the user input. It has a span called "outputNode", which contains the result of JavaScript reading and processing the user input.

Function setResult() copies the content of userInputArea into a string called "userInputString". It then copies userInputString into a string called "outputText". It then calls replaceNodeText(), to replace the contents of outputNode with outputText. (replaceNodeText() is a function in the Head First JavaScript book.)


A friend and I tested entering lines in the textarea, and checking the content of outputNode on the web page. On Windows XP, running Firefox 3.08 and Internet Explorer 8, it ran fine. It also ran fine on Mac OS X 10.5, running Firefox 3.08 and Opera 9.27.

However, I had a problem running Safari 3.21 on Leopard. I put some alerts into a.html, which tell what some counts are. The alerts are triggered by keystrokes. (After you see the alerts, cancel them by clicking on the "OK" button. If you type Enter to cancel the alert, the web page run setResult() becuase you typed a key.)

The problem is that whenever the most recent line that I enter is a blank line, Safari seems to think that there is an extra blank line at the end - a blank line that I didn't enter. Then when I enter a non-blank line, the extra blank line at the end goes away.

For example:

Suppose I type the letter "a". The alerts will say that there is one character in the textarea - the letter "a".

Now I type the "return" key. The alerts will say that I have typed three characters - the letter "a", followed by two carriage returns.

Now I type the letter "b". The alerts will say that I have typed three characters - the letter "a", followed by a carriage return, followed by the letter "b".

If you comment out the alerts so that you're not distracted by them, and the run the test again, you'll see this: After you type a blank line at the end, the "End of the data that you entered" line goes down one line too far, and after you type the "b", the "End of the data that you entered" line moves back up where it should be.

I also tried this on the Safari 4 public beta for Mac OS X. The test worked better with that browser, but it still wasn't right. After I typed a blank line, the "End of the data that you entered" line went down one line too far, and then immediately jumped up to where it should be.

Safari works as I would expect when there are embedded blank lines. I just have problems when the last line is blank.

Am I doing something wrong? Is there a workaround? (This is a simplified version of a web page, which needs the newlines to be correct.)

Thank you very much.
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic