Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:29+00:00 2026-05-31T18:40:29+00:00

I have a signup form with 3 fields: Username Email Password On most browsers

  • 0

I have a signup form with 3 fields:

Username

Email

Password

On most browsers when a user clicks on a particular field, the placeholder value displayed is blanked out so the user can type and if they type nothing and come out of the field the placeholder text re-appears. Anyway some browsers e.g. chrome don’t hide the placeholder text onfocus so I had to write some javascript to take care of this.

I’m quite new to javascript but to me the code I’ve written to deal with this doesn’t seem right. I have a feeling it could be shorter and better.

For each field I have this inside a document ready function:

$("#field_id").focusin(function() {
  $(this)[0].placeholder = "";
});
$("#field_id").focusout(function() {
  $(this)[0].placeholder = "Enter email";
});

My html:

<p><input class="signupFields" data-validate="true" id="user_username" name="user[username]" placeholder="Username" size="30" type="text" /></p>
 <p><input class="signupFields" data-validate="true" id="user_email" name="user[email]" placeholder="Email" size="30" type="text" /> </p>
<p><input class="signupFields" data-validate="true" id="user_password" name="user[password]" placeholder="Password" size="30" type="password" /> </p>

So imagine that times 3 .. Seems like a lot of code for such a simple requirement. Also I really don’t like the fact that I’m trying to mimic javascripts document.getElementById. There must be a way I can do this in a more jQuery like way. Not liking the [0].

Can any body give me an example of a cleaner way of doing this exact same thing?

Kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:40:30+00:00Added an answer on May 31, 2026 at 6:40 pm

    I’d suggest that you don’t need to worry about this, but to remove the placeholder text on focus (and to restore the placeholder on blur) I’d advise the following:

    $('input').focus(
        function(){
            $(this).data('placeholder',this.placeholder).removeAttr('placeholder');
        }).blur(
            function(){
                $(this).attr('placeholder',$(this).data('placeholder')).data('placeholder','');
            });​
    

    JS Fiddle demo.

    The only reason to use the $(this)[0] notation is to ‘break out’ from the jQuery-fied $(this) object back to the native DOM node. To avoid doing that, it’s easier to just this:

    $('input').focus(
        function(){
            this.dataPlaceholder = this.placeholder;
            this.removeAttribute('placeholder');
        }).blur(
            function(){
                this.placeholder = this.dataPlaceholder;
                this.removeAttribute('dataPlaceholder');
            });​
    

    JS Fiddle demo.

    References:

    • blur() (jQuery).
    • focus() (jQuery).
    • data() (jQuery).
    • focus() (jQuery).
    • removeAttr() (jQuery).
    • removeAttribute().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have one signup form where i have three field username,password and email address
I have a signup form of which most fields are pre-filled using user's Facebook
I have a user sign up page with username and password choice fields, I'm
I have a simple login form, username and password. Basically, When a user is
I have a php signup form. I have a text field named username ie,
I have a long signup form and would like to hide a few fields
I have a form allowing a user to signup for a news letter which
It is jQuery . I have a signup form. At the domain textbox field,
I have a two field HTML form for newsletter signup. One field is for
I have signup form on my home screen. If user inputs invalid data I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.