Background text in a text box

I want to display background text in a text box.

ex: Title text box in stackoverflow section Ask a question page.

Required: If I enter text inside a text box, it should disappear.

Gita.

+3
source share
3 answers

For this you need to use javascript.

Use the following two functions in javascript and this is done.

        function clearDefault(obj,val)
        {
            objInput=document.getElementById(obj);
            if(objInput.value==val)
            {
                objInput.value="";
            }
        }
        function setDefault(obj,val)
        {
            objInput=document.getElementById(obj);
            if(objInput.value=="")
            {
                objInput.value=val;
            }
        }

You need to apply it in your code using two javascript events as shown below.

    <input name="email" type="text" class="textbox" id="email" 
  value="Email" size="12" onfocus="clearDefault('email','Email');" 
  onblur="setDefault('email','Email');"/>

, , . Ant .

, !

+1

Well, since you put jquery as a tag for the question, I assume that you are already using jquery for your project. In this case, here is a neat plugin that does the trick: Labelify . Good luck

+1
source

Source: https://habr.com/ru/post/1745736/


All Articles