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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:37+00:00 2026-06-13T12:16:37+00:00

I wanted to change the style of the button I’m using every time I

  • 0

I wanted to change the style of the button I’m using every time I clicked that button and together change it’s text. Problem is I wanted to do it using and external javascript which I’m not that familiar with it’s syntax. To elaborate what I wanted to do is to have a button having a text displaying like: Very Good, Good, Moderate, Failed. Each of the text has it’s own assigned gradient color using CSS let’s say a gradient of Green for Very Good, Yellow for Good, Orange for Moderate and Red for failed. Tried searching for it but I only landed on an irrelevant posts. What I think is that I need to make a button with on click and everytime I click the javascript will add int values from 0 and reset back to 0 after it reaches 3. then I think I can use case for the css class assigning like this.style="failed" Well I don’t know if this is possible.

UPDATE:
After doing some research I’ve managed to do something about the changing texts (using javascript alone) but not yet the class part since I think the class is a keyword in javascript. here’s my script so far:

    function buttonChange(){
    var button = document.getElementById("stats");
    switch (button.value)
    {
      case "Very Good":
      button.value="Good";
      break;
      case "Good":
      button.value="Moderate";
      break;
      case "Moderate":
      button.value="Failed";
      break;
      default:
      button.value="Very Good";
    }       
}

now the problem is the style. 🙂

  • 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-13T12:16:38+00:00Added an answer on June 13, 2026 at 12:16 pm

    Using jQuery your code could look something like this:

    var values = new Array('Very Good', 'Good', 'Moderate', 'Failed');
    var colors = new Array('lime', 'yellow', 'orange', 'red');
    
    $('#rate').click(function() {
    
        // current index is stored in data attribute
        var idx = $(this).data('value') + 1;
    
        // last value was selected -> go back to first one
        if (idx >= values.length) {
            idx = 0;
        }
    
        // update data attribute with current index
        $(this).data('value', idx);
    
        // update button text
        $(this).val(values[idx]);
    
        // update button background color
        $(this).css('background-color', colors[idx]);
    
    });​
    

    See this FIDDLE.

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

Sidebar

Related Questions

i'm struggling with display/hide text using javascript here. Here is what i wanted to
I wanted to change the animation that occurs on a navigationControllers toolbar when the
I'm just messing around learning about JavaScript and I wanted to change the color
I have a style guide from a designer for a button that looks like
What exactly I wanted is to change the Notification Alert Style to Alerts But
I wanted to write a javascript code that will slide a div in specific
<html> <head> <script type=text/javascript> function changepic() { document.getElementById(demo).style.top=2000; } </script> </head> <body> <h1>My First
I have a style for a ComboBox that I've been using for awhile, but
i wanted to make the button such that if button A is click, A
I wanted to change a tag from being local to global by deleting and

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.