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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:16:42+00:00 2026-06-11T21:16:42+00:00

I would like to know how to write the javascript to alter the style

  • 0

I would like to know how to write the javascript to alter the style of form elements which are required; and change them if they have values in them.

What I want to do is have a colored border around the required text fields when they are blank, and remove the border style when they have values.

what I’ve thought of doing is to write a single javascript function which checks if the value is empty and set the appropriate style:

function requiredElement(id) {
  var Input = document.getElementById(id);
  if(Input.value==null) {
    Input.style.border = '2px solid #FF0000';
  }
}

But what I’m stuck with is changing the style as user enters/removes characters in these required fields, and calling the function for the fields.

I have a simple html form, each input has a unique ID.

  • 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-11T21:16:43+00:00Added an answer on June 11, 2026 at 9:16 pm

    Use jQuery

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
    

    Then add this code:

    $('.important').change(function() {
      if(($(this).val()) != '') $(this).css( 'border-width', '0' );
      else  $(this).css( 'border-width', '2' );
    });
    

    Assuming you added a border in the css

    .important
    {
        border-style:solid;
        border-width:2px;
        border-color:red;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to test out some interviewees by having them write some javascript
I would like to know, which is the best way to write an url
I would like to know how to write a Macro to copy the value
I would like to know how to write this inside my hittest if statement:
I would like to know how can I write a pointer array: short* myArray
I would like to know if its possible to write a nested select statment?
I would like to know how can i write to a file within Application.
I have some javascript I would like to execute only if a user is
I have build a game using canvas and Javascript, and I would like to
I am rewriting some old JavaScript with jQuery and would like to know how

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.