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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:39:29+00:00 2026-06-08T21:39:29+00:00

Hard to define the title ^^ I want to have to input fields. For

  • 0

Hard to define the title ^^

I want to have to input fields. For example: one where you type in a color (string) and another for the code of the color (varchar).

Like this: |Green| |#657EC9| (just random color-code)

I do not want to learn how to find the color-code but how to match a value or variable with another. It was just an example.

What i wanna know is how I in the best way auto generate one of the fields when I fill in the second. When I type ‘green’ in the first field I want the code to automatically appear in the second and vice versa. I just want to do it for a few colors.

I am very new to PHP, HTML and Javascript and could need some good advice about how I should handle the problem.

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-06-08T21:39:31+00:00Added an answer on June 8, 2026 at 9:39 pm

    I would tend to just map values to an object literal, so:

    var colors = {
        Green:'#657EC9',
        Red:'#00ffff'
    }
    

    Now you could get your value with colors[fieldInputVal] where fieldInputVal might be ‘Green’ or ‘Red’ although of course you’d have to test if there actually was a property there. Object literals are the main reason I rarely find a use for switch statements in JS.

    As for the event JS, I’m going to be lazy and go with JQuery rather than explain attachEvent vs. addEventListener which would be necessary if you’re supporting IE8 or below. If you want to normalize for that yourself and skip JQuery, look up ‘addEvent contest’ on quirksmode.org

    $('.input_one').change( function(){
        //note: only fires after the field loses focus - you tab out or focus another field
        var inputVal = $(this).val();
        if(colors[inputVal] !== undefined){
            $('.input_two').val(colors[inputVal]);
        }
    } );
    

    note: I did not test this code for syntax goofs.

    If you want to be more flexible and accept ‘green’ or ‘Green’, I would just capitalize the first character before you use it for the lookup. To do the lookup on every character add, you’d have to look up the keyup or keydown events (I prefer keyup to avoid breaking the browsers back when somebody holds a key down).

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

Sidebar

Related Questions

Hey its really hard to define an exact title for my problem. I am
I have a C program which has always used hard coded define statements for
I have hard-coded data into a .jsp file. What I want to do is
Something I have never thought too hard about but I am curiuos and want
I'm having a hard time understanding this piece of code. #define TABLE \ STATE(STATE_1,
Sorry for the vague thread title; hard to succinctly describe my question. I have
Apologies for the title, I found it hard to define my question succintly and
Hard to come up with a proper title for this problem. Anyway... I'm currently
Kinda hard to explain, but i'll try. I have a datalist that is populated
The hard drive on one of my PCs crashed that had the installers for

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.