[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Finding line breaks in multiline textbox value

Posted on 2005-04-19
5
Medium Priority
?
278 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:ddetering
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13816504
why dont u try

onFocus="if (this.value.indexOf('Hi! Check out this site!') != -1 )this.value = ''
0
 
LVL 15

Accepted Solution

by:
justinbillig earned 500 total points
ID: 13816525
try this

onfocus=" if( this.value == this.defaultValue ){ this.value = ''; }"
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13816528
oops shud be == -1
and not

!= -1
0
 
LVL 1

Author Comment

by:ddetering
ID: 13816640
Perfect solution, justinbillig!
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 13817202
No problem.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question