I have simple routine to show tips in the textarea to the users. If the user focuses on the textarea and there is no user input, the script clears the tips. If the area is blurred without user inputs, the area shows the the tips.
This seems to work fine in IE and chrome, but firefox 3.6 does not seem to work every time.
Click the textarea to focus, the textarea clears the text
Don’t type anything and click outside to unfocus the textarea, the tip will show.
Click the textarea again to focus, but the text won’t disappear.
Click outside to unfocus
Click the textarea again to focus, this time the text area will clear the text.
Any tip or insight to correct this behavior for firefox 3.6?
TIA
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../jquery-1.6.4.min.js"></script>
</head>
<body >
<div style="text-align:center">
<textarea id="btext" onfocus="clearOnFocus()" onblur="showtip()">
Enter text
</textarea><br>
</div>
<!-- end page -->
<script language="javascript">
function clearOnFocus () {
//alert ('test');
var patt=/Enter text/g;
var result=patt.test($('#btext').val());
if (result) {
$('#btext').val('');
}
}//end of clear
function showtip () {
var textinput = $('#btext').val();
if (textinput == '') {
var btips = 'Enter text';
$('#btext').val(btips);
}
}//end of showtip
</script>
</body>
</html>
you can use a regular expression to test that the value is something other than just whitespace. You can also test against the default value to see if anything has beeen entered. That way your script is independent of the value of the textarea.