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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:22:35+00:00 2026-05-23T19:22:35+00:00

I am writing a small script to test if a form has been altered

  • 0

I am writing a small script to test if a form has been altered before it has been submitted. So normal inputs (text, textarea, etc) I can use:

if(element.defaultValue != element.value) {
    altered[element.name] = element.value;
    element.value = element.defaultValue;
}

This works fine. But it appears the select inputs don’t have one to check against. Although in Firebug it does appear in the DOM listing, but in black (instead of green) which I believe means that it’s added by the browser (correct me if I’m wrong).

If I log the element.defaultValue for a select element it returns undefined.

So my question, does select have a defaultValue attribute? Or some alternative that I can leverage?

  • 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-23T19:22:36+00:00Added an answer on May 23, 2026 at 7:22 pm

    If you are not setting a default selected option on the <select> element (or if you are always selecting the first option as the default), you can try:

    if(element.selectedIndex && element.selectedIndex != 0) {
        //this handles <select> inputs
        altered[element.name] = element.options[element.selectedIndex].value;
        element.selectedIndex = 0;
    }
    else if(element.defaultValue != element.value) {
        //this handles any other kind of input (except not really for checkbox, radio, etc.)
        altered[element.name] = element.value;
        element.value = element.defaultValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small shell script that needs to reverse the lines of a
I am writing a small app which I need to test with utf-8 characters
i'm writing a small script to tweet messages from the monitoring systems. The only
I'm currently writing a small script for use on one of our servers using
I'm writing a small PHP script to grab the latest half dozen Twitter status
I'm writing a small script to see if certain ports on certain devices are
I'm writing a small script (similar to SO's tag RegEx) that only allows the
I'm writing a small script to open mailto links from webpages in google chrome
I'm writing a small script to learn how to parse an XHTML web page.
Hi I am writing a small jQuery script which will toggle a hidden Top-Panel

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.