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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:09:13+00:00 2026-05-14T05:09:13+00:00

I need to clear the default values from input fields using js, but all

  • 0

I need to clear the default values from input fields using js, but all of my attempts so far have failed to target and clear the fields. I was hoping to use onSubmit to excute a function to clear all default values (if the user has not changed them) before the form is submitted.

<form method='get' class='custom_search widget custom_search_custom_fields__search' onSubmit='clearDefaults' action='http://www.example.com' >
<input name='cs-Price-2' id='cs-Price-2' class='short_form' value='Min. Price' />
<input name='cs-Price-3' id='cs-Price-3' class='short_form'  value='Max Price' />
<input type='submit' name='search' class='formbutton' value=''/>
</form>

How would you accomplish this?

  • 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-14T05:09:14+00:00Added an answer on May 14, 2026 at 5:09 am
    • Read the ids+values of all your fields when the page first loads (using something like jquery to get all “textarea”, “input” and “select” tags for example)
    • On submit, compare the now contained values to what you stored on loading the page
    • Replace the ones that have not changed with empty values

    If it’s still unclear, describe where you’re getting stuck and I’ll describe more in depth.

    Edit: Adding some code, using jQuery. It’s only for the textarea-tag and it doesn’t respond to the actual events, but hopefully it explains the idea further:

    // Keep default values here
    var defaults = {};
    
    // Run something like this on load
    $('textarea').each(function(i, e) {
      defaults[$(e).attr('id')] = $(e).text();
    });
    
    // Run something like this before submit
    $('textarea').each(function(i, e){
      if (defaults[$(e).attr('id')] === $(e).text())
        $(e).text('');
    })
    

    Edit: Adding some more code for more detailed help. This should be somewhat complete code (with a quality disclaimer since I’m by no means a jQuery expert) and just requires to be included on your page. Nothing else has to be done, except giving all your input tags unique ids and type=”text” (but they should have that anyway):

    $(document).ready(function(){
      // Default values will live here
      var defaults = {};
    
      // This reads and stores all text input defaults for later use
      $('input[type=text]').each(function(){
        defaults[$(this).attr('id')] = $(this).text();
      });
    
      // For each of your submit buttons,
      // add an event handler for the submit event
      // that finds all text inputs and clears the ones not changed
      $('input[type=submit]').each(function(){
        $(this).submit(function(){
          $('input[type=text]').each(function(){
            if (defaults[$(this).attr('id')] === $(this).text())
              $(this).text('');
          });
        });
      });
    });
    

    If this still doesn’t make any sense, you should read some tutorials about jQuery and/or javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In several places I have to retrieve some value from a dict, but need
i have a input tag which is non editable, but some times i need
I need to have my Django application allow me to have a default value
I have several modules (mainly C) that need to be redesigned (using C++). Currently,
I need to clear the read-only flag of a file in my Perl program
I need a very simple and clear example of how to create an OCX
need ask you about some help. I have web app running in Net 2.0.
what is the best way of extracting multiple (~40 values) from a text file
Sorry for my Noobness with Excel/Vba... coming from a unix world...I need help! I
I have the following input <row test=1 /> and want to generate the following

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.