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

  • SEARCH
  • Home
  • 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 8313829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:37:30+00:00 2026-06-08T20:37:30+00:00

How can I clear the default value of an input form onfocus with jquery

  • 0

How can I clear the default value of an input form onfocus with jquery and clear it again when tha submit button is pressed?

<html>
        <form method="" action="">
            <input type="text" name="email" value="Email address" class="input" />
            <input type="submit" value="Sign Up" class="button" />
        </form>
</html>

<script>
$(document).ready(function() {
    //hide input text
    $(".input").click(function(){
        if ($('.input').attr('value') == ''){
            $('.input').attr('value') = 'Email address'; alert('1');}
        if  ($('.input').attr('value') == 'Email address'){
            $('.input').attr('value') = ''}
    });
});
</script>
  • 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-06-08T20:37:31+00:00Added an answer on June 8, 2026 at 8:37 pm

    You may use this..

    <body>
        <form method="" action="">
            <input type="text" name="email" class="input" />
            <input type="submit" value="Sign Up" class="button" />
        </form>
    </body>
    
    <script>
        $(document).ready(function() {
            $(".input").val("Email Address");
            $(".input").on("focus", function() {
                $(".input").val("");
            });
            $(".button").on("click", function(event) {
                $(".input").val("");
            });
        });
    </script>
    

    Talking of your own code, the problem is that the attr api of jquery is set by

    $('.input').attr('value','Email Adress');
    

    and not as you have done:

    $('.input').attr('value') = 'Email address';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i have default values for my input's, and when user submites form,
I want a basic: <input type=text /> And I would like the default value
I'm creating a table of an arrays where the user can input the value
I was trying to clear input text using onfocus and onblur inside the input
I have 2 sets of 4 input fields in my HTML Form. I expect
I've created a simple auto-complete control using JQuery UI. I have a default value
I have a jQuery script below that clears the value of an input on
I know you can clear options by doing the following: dropDownList.options.length = 0; Is
Hoping someone can clear this up for me. Let's say I have 2 globals:
Can I clear browser cache of the page when I'm leaving it. // Clear

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.