Reputation: 199
I'd like the following code to be change so that the textarea has a default value that disappears when it's focused.
if ($txtActive != 'N') {
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "";
echo "<tr>";
echo "<th align='" . $labelAlign . "'></th>";
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols'>" . stripslashes($value) . "" . "</textarea>";
echo ($txtError) ? "<br /><b style='color: $errorTxtColor;'>$txtError</b>" : '';
// echo "wendy TESTerburger";
echo "</td>";
echo "</tr>\n";
Upvotes: 4
Views: 1711
Reputation: 199
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value='Comments...' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Comments...')this.value='';\" onblur=\"if(this.value=='')this.value='Comments...';\">" . stripslashes($value) . "Comments..." . "</textarea>";
Upvotes: 0
Reputation: 10091
You need to use the placeholder
attribute. Note that it's part of the HTML5 spec, only works with the latest versions of some browsers. If you want it to work in older browsers, you'll need to do it with Javascript.
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' placeholder='Default text'>" . stripslashes($value) . "" . "</textarea>";
Here's an example of doing it with Javascript:
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Default value')this.value='';\" onblur=\"if(this.value=='')this.value='Default value';\">" . stripslashes($value) . "" . "</textarea>";
Very simple.
Upvotes: 1
Reputation: 490303
Any client side interaction won't use PHP - but your in client friend, JavaScript.
I wrote a jQuery plugin that does this in a cross browser fashion.
If only targeting modern standards compliant browsers, use the placeholder
attribute.
Upvotes: 1
Reputation: 4283
If I'm understanding the question properly, you would change this line, like so:
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "Default Text";
So if mod_SEF_textarea was not set, i.e. no value, the false clause would execute, which would be your default.
Upvotes: 1