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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:44:09+00:00 2026-05-23T07:44:09+00:00

I’ve got this code which sets dynamic maximum values for two text boxes: var

  • 0

I’ve got this code which sets dynamic maximum values for two text boxes:

var length = document.getElementById('firstBox'),
    width = document.getElementById('secondBox');
    max1 = 100;
    min1 = 20;
    max2 = 200;
    min2 = 10;

length.onchange = function() {
    var maxValue, minValue;

    if (width.value < max1) {
        maxValue = max2;
        minValue = (width.value < min1) ? min1 : min2;
    } else {
        maxValue = max1;
        minValue = min1;
    }
    if (this.value > maxValue) {
        this.value = maxValue;
    }
    if (this.value < minValue) {
        this.value = minValue;
    }
};

width.onchange = function() {
    var maxValue, minValue;

    if (length.value < max1) {
        maxValue = max2;
        minValue = (length.value < min1) ? min1 : min2;
    } else {
        maxValue = max1;
        minValue = min1;
    }
    if (this.value > maxValue) {
        this.value = maxValue;
    }
    if (this.value < minValue) {
        this.value = minValue;
    }
};

It works very well, only I would like to have the maximum (max2) switch to the other box if the customer types in a value higher than the lowest maximum (max1) in that box.

Say a customer types “150” in box one, then that box automatically gets assigned max2 “200” – but what I want, is if the customer then also types “150” or any value higher than max1 in the second box, then that should become the max2, meaning the first box will be lowered from it’s “150” to “100” as is the max1. And vice versa.

Hopefully that’s understandable, otherwise let me know and I’ll try to explain it better.

  • 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-23T07:44:10+00:00Added an answer on May 23, 2026 at 7:44 am

    The idea is instead of holding the variables firstbox and secondbox to hold pointer variables to the box that conforms to max1 max1box and the box that conforms to max2, max2box.

    In the case the logic dictates to switch maxes, you just switch the pointers around.

    var max1box = document.getElementById('length'),
        max2box = document.getElementById('width');
        max1 = 100;
        min1 = 20;
        max2 = 200;
        min2 = 10;
    
    max1box.addEventListener('change',validateValues);
    max2box.addEventListener('change',validateValues);
    
    function validateValues() {
    
        if (this == max1box && this.value > max1 && this.value > max2box.value)
        {
           max1box = max2box; 
           max2box = this;  
        } 
    
        if (max1box .value > max1) {
            max1box .value = max1;
        }
        if (max1box .value < min1) {
            max1box .value = min1;
        }        
    
        if (max2box.value > max2) {
            max2box.value = max2;
        }
        if (max2box.value < min2) {
            max2box.value = min2;
        }
       }
    

    You can see it in action here: http://jsfiddle.net/Hm2Qn/1/

    The rules when to switch might not be exactly what you need but you can take it from here.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.