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

  • Home
  • SEARCH
  • 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 6563893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:54:05+00:00 2026-05-25T13:54:05+00:00

How do I compare the values in the text fields with the same data

  • 0

How do I compare the values in the text fields with the same data attribute in javascript?

<input type="text" name="a" id="a" data-common="candy" class="loop" value="2">
<input type="text" name="b" id="b" data-common="candy" class="loop" value="3">
<input type="text" name="c" id="c" data-common="ice" class="loop" value="7">
<input type="text" name="d" id="d" data-common="ice" class="loop" value="2">
<input type="text" name="e" id="e" data-common="water" class="loop" value="5">
<input type="text" name="f" id="f" data-common="water" class="loop" value="9">

What I want to do is to determine the higher value on each of the fields with common data attribute. If the common attribute is candy, then the program will compare the values 2 and 3.
My problem is I can’t think up of a good algorithm to even start coding. Can you give me an idea? What do I need to do first.

  • 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-25T13:54:06+00:00Added an answer on May 25, 2026 at 1:54 pm

    Here you go. The below code will find all the unique data-common attributes with max value.

    Working demo

    var dataAttributes = {}, attrValue, inputValue, $this;
    $('input[data-common]').each(function() {
        $this = $(this);
        attrValue = $this.attr("data-common");
        inputValue = parseInt($this.val());
        if(!dataAttributes[attrValue]){
            dataAttributes[attrValue] = inputValue;
        }
        else{
            if(dataAttributes[attrValue] < inputValue){
                dataAttributes[attrValue] = inputValue;
            }   
        }
    });
    console.log(dataAttributes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this form: <form method=post action= accept-charset=utf-8> <p> <label>first_field</label><br /> <input type=text id=first_field
I am using a custom validator to compare value in two text box. This
Can someone suggest a way to compare the values of two dates greater than,
I am trying to compare two decimal values in Java script. I have two
What would be a better approach to compare two floating point values - using
Does a comparison sort have to compare the A[i] largest and A[i+1] largest values?
I've got an application that's using string.compare(string,string) to sort some values. The thing I
today1 = new Date(); today2 = Date.parse(2008-28-10); To compare the time (millisecond) values of
I am parsing text that has a heading and then data that applies to
I have a small struct and I have to compare the values to find

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.