Question:

How do you make default text in the text field?

by  |  earlier

0 LIKES UnLike

I want text to appear in the text field by default, like to say "Put your description here" but then when you click on it, it disappears. Similar to when asking a question on yahoo answers, it says "What would you like to ask" and then when you click there to type, it goes away? (i'm using ruby on rails if that's needed) ThANKS

 Tags:

   Report

1 ANSWERS


  1. Hello,

    Basically to make  the text appear by default it is:

    <input type='text' value='Your Default Value' name='fieldname' id='fieldid' />

    And you have to use javascript to remove the text. Before he </head> section add the  following script

    <script language='javascript'>

    function removedefault()

    {

    var elm = document.getelementbyid('fieldid');

    elm.value = "";

    }

    </script>

    And rewrite the input box as:

    <input type='text' value='Your Default Value' name='fieldname' id='fieldid' onclick="removedefault();" />

    That should do the trick.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.