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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:27:43+00:00 2026-06-15T13:27:43+00:00

Possible Duplicate: How do I change the background color with Javascript? I have this

  • 0

Possible Duplicate:
How do I change the background color with Javascript?

I have this javascript function which works fine but I wanted to add to it.

The Risk is calculated by multiplying the severity by the likelihood. The calculation is done by the function below validate_form()

The colour according to values is:

  • Green – less than 6 the input field changed colour to green
  • Orange – between 6 – 9
  • Red – if more than 9

The risk value writes to and input field named “risk1” “risk2” etc.

function validate_form ( ) {
    valid = true; 

    document.calc.risk1.value = document.getElementById('data_1_severity').value*document.getElementById('data_1‌​_likelihood').value;
    document.calc.risk2.value = document.getElementById('data_2_severity').value*document.getElementById('data_2‌​_likelihood').value; 

    return valid;
}

Could someone help me with this? Just want either the risk score to change color depending on value or the background of the cell to change colour – not really bothered. This will show then if the risk is:

  • Green – Low Risk
  • Orange – medium risk
  • Red – high risk.
  • 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-15T13:27:44+00:00Added an answer on June 15, 2026 at 1:27 pm

    Something like this:

    var changeColor = function(obj){
    
      if(obj.value < 6){
        obj.style.backgroundColor = 'green';
      } else if(obj.value >= 6 && obj.value <= 9){
        obj.style.backgroundColor = 'orange';
      } else if(obj.value > 9){
        obj.style.backgroundColor = 'red';
      }
    
    };
    

    Then inside your validate_form() function:

    changeColor(document.calc.risk1);
    

    Even better would be to create CSS classes for each color and do something like:

    obj.className = 'green';
    

    instead of

    obj.style.backgroundColor = 'green';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Function triggering early I have whipped up this code, but why on
Possible Duplicate: Why does the background of TextView change it's size? I have a
Possible Duplicate: change colors of table with javascript for this problem im trying to
Possible Duplicate: Change custom color for Rectangle.Fill or Grid.Background I'm trying to dynamically set
Possible Duplicate: Change background color of UI elements in eclipse IDE As you all
Possible Duplicate: change background color of li using jquery I'm trying to change background
Possible Duplicate: Change color of selection How does this site manage to make text
Possible Duplicate: Background color of a ListBox item (winforms) I have a ListBox, that
Possible Duplicate: JQuery DatePicker background color Am using the folllowing function for pick the
Possible Duplicate: Android Button: set onClick background image change with XML? I need that

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.