Javascript: Properly Setting A Text Area
I have a text area and the problem is people are typing a large amount of text and I have it clearing out the value and forcing an N/A so I can force something to be entered. How can I make the script below validate someone has already typed something (and not clear it out) but still clear out the N/A by default?
<textarea name="req_WhatMadeItDifficultToUse" cols="35"
onfocus="this.value = '';"
onblur="if(this.value == '') this.value = 'N/A';"
id="W开发者_开发知识库hatMadeItDifficultToUse">N/A</textarea>
You can change this:
onfocus="this.value = '';"
To this:
onfocus="if(this.value == 'N/A') this.value = '';"
This way you're only clearing it if it had the string N/A
, this is how the search box on this page works, click it, watch search go away, type "search" in there, click out and back in...it's just clearing if "search" was the term...perfectly acceptable behavior :)
As an aside, is binding these events externally an option, or any sort of framework? Either would make your life much easier, but not sure if they are an option you have.
精彩评论