Jump to content


Photo

Javascript paste? I need help please


  • Please log in to reply
1 reply to this topic

#1 da_cracken

da_cracken
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 04 September 2006 - 12:13 AM

Hi,
   I need help please. I'm working on a script to paste items into a text area. The scipt pastes, but it pastes where it wants to paste, and not where i want it to go. I want it to paste at the text selector, but it only pastes at the very end of any text already in the box. I have pasted a small part of the script below and I pray someone can figure out the error of my ways for me ;D

function BR()
{
document.Pro.write.value += ("<BR>\n")
}

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 12:46 AM

Because that is what you are telling it do. The += adds whats on the right to the end of whats on the left. So its always going to add <br> on to the end of whats in you textarea

If you want to get javascript to add <br> where your curser is, then it'll be a bit more advanced as you'll have to use javascript find out where the curser is located to and then get it to add br tag in that location.

Also whay are you adding br tag into a textarea anyway? If its to preserver line breaks. Dont bother just use the nl2br PHP function to preserve the line breaks.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users