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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops shud be == -1
and not
!= -1
and not
!= -1
ASKER
Perfect solution, justinbillig!
No problem.
onFocus="if (this.value.indexOf('Hi! Check out this site!') != -1 )this.value = ''