Link to home
Start Free TrialLog in
Avatar of ddetering
ddetering

asked on

Finding line breaks in multiline textbox value

Hi!

I have a prepopulated textbox (in ASP.net) that I want to clear on focus. The prepopulated text contains line breaks and I am unable to have JavaScript match that text with line breaks. For example, this is the textbox value:
Hi!
Check out this site!

and this is the JavaScript:

onFocus="if (this.value == 'Hi!\nCheck out this site!') this.value = ''

I had tried \r and \n\r to no avail, but have no problems when there is no line break in the to-be-removed default text. (I need to test for the default in order to prevent the script deleting custom-entered text)

Thanks for helping!
Avatar of archrajan
archrajan

why dont u try

onFocus="if (this.value.indexOf('Hi! Check out this site!') != -1 )this.value = ''
ASKER CERTIFIED SOLUTION
Avatar of justinbillig
justinbillig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops shud be == -1
and not

!= -1
Avatar of ddetering

ASKER

Perfect solution, justinbillig!
No problem.