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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:49+00:00 2026-05-27T11:32:49+00:00

I am working on somethign where I have two input fields, one for a

  • 0

I am working on somethign where I have two input fields, one for a primary color and one for a secondary color. I am using JSColor so when you click on the input box a color picker comes up, and when you change the color, the background of the input changes to that color.

Well I want to have another feature where I can have some “premade” colors that someone can choose form. So here is what I have:

<a id="standardTheme">Standard Theme</a>
<a id="themeTwo">Theme Two</a>

and so forth. And the jQuery I have is:

$('#standardTheme').click(function() {
    var primaryPicker = new jscolor.color(document.getElementById('primaryColor'), {})
        primaryPicker.fromString('FF0000')

    var secondaryPicker = new jscolor.color(document.getElementById('secondaryColor'), {})
        secondaryPicker.fromString('000000')
});

Which works perfect. Well for themeTwo I would have to duplicate that whole code and manually enter in new hex colors that I want for theme two.

I might have 5 or 6 themes to choose from so that could get very long. I was wondering if anyone could help me improve on the code if there is an easier way to do that and shorter and more flexible for when I want to add more themes?

Thank you!

  • 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-27T11:32:49+00:00Added an answer on May 27, 2026 at 11:32 am

    Why not simply associate data with the button you are clicking?

    <button class="themeButton" data-primary-color="FF0000" data-secondary-color="000000">Standard</button>
    

    Then in jQuery:

     $('.themeButton').click(function()
     {
         var primaryColor = $(this).data('primary-color');
         var secondaryColor = $(this).data('secondary-color');
    
         // OR the more verbose way
    
         var primaryColor = $(this).attr('data-primary-color');
         var secondaryColor = $(this).attr('data-secondary-color');
    
         // Do your code with the primary and secondary color text
     });
    

    You can then extend as many times as you need by placing however many buttons you need as long as you set the attributes on each button appropriately. You then share the callback among all buttons.

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

Sidebar

Related Questions

basically I have two input fields, name and username. The idea is that the
I'm trying to have two functions checking each form input, one for onchange() and
Here is my programme, which have a two threads, one is listening user input,
I have these two in my html code: <input class=input1 type=text size=15 name=login> <input
I currently have an input form. There are two entries for each input class
I started using the MoveMe sample to get touch input working. basically, I define
I am working on something where i have a table C with two columns
I am willing to develop a mobile application. I wish to have something working
I'm working on a thread library which implement user level threads (i have something
I'm working on configuring a RollingFileAppender in log4net programmatically. I have something like this

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.