Hello!

There is a text field, let it be the login, it is generated by the module through some kind of system. The source code could not be found - as it is generated - but there is its id=#mb6b22feu_input_username . I want to make sure that when I focus on this input, I’ll remove the inscription "Login" to an empty value. How to do, I already understood

 if (this.value == 'Логин'){ this.value = ''; } 

But the problem is that there is no default text, it is necessary that the default was the text Login. It is necessary to do this somehow via jQuery, since I could not find the source for generating this form! Help people? Below is the complete jquery code:

 $(document).ready(function () { $('#mb6b22feu_input_username').focus(function () { if (this.value == 'Логин') { this.value = ''; } }); }); 

    4 answers 4

     $(document).ready(function () { $("mb6b22feu_input_username").val("Логин"); $('#mb6b22feu_input_username').focus(function () { if (this.value == 'Логин') { this.value = ''; } }); }); 
    • I believe that it is impossible to make such inscriptions in this particular way. The input must remain empty, and the inscription in the transparent layer above the input must be that the focus passes through itself. - MuFF

    The inscription at the focus can be done

      $result = mysql_query("SELECT `login` FROM `users`"); $r = mysql_fetch_array($result); $login= $r['login']; <input onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" value="$login" /> 

    Initially, data is being sampled from the database.

    Then assign the login field $ login variable

    Well, insert this variable into the string.

    ATTENTION: this will fetch all logins from the database from the login line,

    for this you need to write a condition.

    • Have you read the question carefully? TC can not find the source in which the form is generated and therefore uses jquery to set the default value. Sampling from the database and inserting the selected login into the field is no less obsurden. After logging in, these fields are hidden, for example, to place a link / button Exit. - Sharpness

    Children, it is called placeholder , it is supported by fresh browsers, and for the others there is placeholder.js .

    • Exactly. You can simply register <input placeholder = "login" /> in the tag. Well , attach a library to the HTML5 page page www.modernizr.com - webkostya
    • Do not forget, this inscription will disappear when placing the cursor in input - I_CaR
    • Will not be. placeholder disappears only when we start to write something, and rightly so - Snow

    I just stumbled upon a great plugin for this purpose and immediately hurried here to report)

    • There is one drawback to all this - If I want to enter text that matches the text I want to see with a hint, the value of the input is reset :-( But with a little refinement, this can be solved :-) - Chad