DevelopPHP.com 2011 Forum Discussion(not active)


Watermark for textareas or textfields
May 07, 2011 Merox wrote:
I have a textarea where the user posts comments with onfocus watermark message, but the watermark does not display until the user clicks inside and then outside the textarea. What's wrong with the code?
Re:Watermark for textareas or textfields
May 07, 2011 wormracer08 responded with:
Where's the code?
Re:Watermark for textareas or textfields
May 07, 2011 Merox responded with:

Here it is.

function boardbox_focus(){
 var boardboxid  = document.getElementById("boardbox");
 if (boardboxid.value == "Share something...") {
  boardboxid.value = "";
  boardboxid.style.color = "#000000";
 }
}

function boardbox_blur(){
 var boardboxid  = document.getElementById("boardbox");
 if (boardboxid.value == "") {
  boardboxid.value = "Share something...";
  boardboxid.style.color = "#A6A6A6";
 }
}

And then the form.

<form action='profile.php' method='post' enctype='multipart/form-data'>
  <textarea name='board' rows='3' style='width:94%;' id='boardbox' onblur='boardbox_blur();' onfocus='boardbox_focus();' class='boardBoxInput' title='Write Here'></textarea>
  <input type='submit' name='boardbtn' style='margin-top: 3px;' value='Share' />
  </form>

Re:Watermark for textareas or textfields
May 07, 2011 wormracer08 responded with:

<form action='profile.php' method='post' enctype='multipart/form-data'>
<textarea style='color:#a6a6a6;' name='board' rows='3' style='width:94%;' id='boardbox' onblur='boardbox_blur();' onfocus='boardbox_focus();' class='boardBoxInput' title='Write Here'>Share something... </textarea>
<input type='submit' name='boardbtn' style='margin-top: 3px;' value='Share' />
</form>

Re:Watermark for textareas or textfields
May 07, 2011 Merox responded with:

I have tested already and is not working with the javascript. I'm looking for a similar effect like facebook's wall form.

Any advice?

Re:Watermark for textareas or textfields
May 07, 2011 wormracer08 responded with:

humm, worked for me.

Use jQuery it will make your life easier

This is totally on a whim, not tested at all, it's Saturday night and I've had a few....lol

$(document).ready(function() {

    $('#boardbox').focus(function() {

        $(this).value() = '';

});

 

     $('#boardbox').blur(function() {

           $(this).value() = 'Share something';

      });

});


©2011 DevelopPHP.com