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 8232275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:46:46+00:00 2026-06-07T17:46:46+00:00

I have a form in my sidebar that is part of a WordPress plugin

  • 0

I have a form in my sidebar that is part of a WordPress plugin and I’m not sure where the PHP code that generates the form resides, so I’d like to add a class and a value to the text input using jQuery. So far I have:

$j('body').ready(function() {
    $j('form#searchform').find(':input#s').addClass('default-value');
    $j('form#searchform').find(':input#s').val('enter search here...');
});

The class is added successfully to the html, but though the value shows in the text input, it is not added to the html, i.e. within the tag, which needs to happen for my default value script to work. So, I’m wondering if there is a way of adding the value inline?

DEFAULT VALUE SCRIPT

  $j('.default-value').each(function() {
      var default_value = $j(this).val();
      $j(this).css('color', '#837D73'); // this could be in the style sheet instead
      $j(this).focus(function() {
          if(this.value == default_value) {
              this.value = '';
              $j(this).css('color', 'black');
          }
      });
      $j(this).blur(function() {
          if(this.value == '') {
              $j(this).css('color', '#837D73');
              this.value = default_value;
          }
      });
  });
  • 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-07T17:46:47+00:00Added an answer on June 7, 2026 at 5:46 pm

    Your code should be working. Just make sure you add the class name
    http://jsfiddle.net/fedmich/NbRBe/

    and notice the

    var default_value = this.value; //<-do it like this instead
    

    Tip: you should try to use jquery chaining

    You could simplify your code like this.

    $j('body').ready(function() {
        $j('input#s')
            .addClass('default-value')
            .val('enter search here...');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form, where some fields are looks like rows, so I can add/delete
I have form like this : <div id='add_field' class='locbutton'><a href='#' title='Add'>Add</a></div> <div id='remove_field' class='locbutton2'><a
I have sidebar.php in my views folder. It contains this code: <div class=title_box> Login
I have a form partial that is being called in a content_for :sidebar. This
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I'm looking for a wordpress plugin that hides to start with the when I
I have a blog that has a sidebar with a partial view in it
I want to build a login form that displays in a sidebar across every
Not sure if that was the best way to phrase what I'm trying to
I have a sidebar widget that has an image background. Over this is a

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.