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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:11:50+00:00 2026-06-08T07:11:50+00:00

I have two select form fields. One is the price_from, the other is price_to.

  • 0

I have two select form fields. One is the “price_from”, the other is “price_to”. The problem is that I want to prevent the user for selecting for example price_from “10000” and price_to “1000”, so basically I must find some javascript function which sets the “price_to” field values based on “price_to” values onwards. ie : If I select the price_from =”3000″, the price_from field will display values from “4000”. And ofcourse vice-versa. If somebody changes the “price_to” or “price_from” field again.

  • 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-08T07:11:51+00:00Added an answer on June 8, 2026 at 7:11 am

    Try this:

    HTML:

    <select id="from1" relatedTo="to1">
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
    </select>
    
    <select id="to1" relatedTo="from1">
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
    </select>
    
    <br/>
    
    <select id="from2" relatedTo="to2">
        <option value="100">100</option>
        <option value="200">200</option>
        <option value="300">300</option>
        <option value="400">400</option>
    </select>
    
    <select id="to2" relatedTo="from2">
        <option value="100">100</option>
        <option value="200">200</option>
        <option value="300">300</option>
        <option value="400">400</option>
    </select>
    

    JavaScript:

    // function to valide two selects
    function validateSelects( fromSelector, toSelector ) {
    
        // registering the change event to the "to" select
        $( toSelector ).change(function() {
    
            var fromSelector = "#" + $(this).attr( "relatedTo" );
            var toSelector = "#" + $(this).attr( "id" );
    
            // compares the value of the selected item with the from select
            if ( $(this).val() > $( fromSelector ).val() ) {
    
                // selects the value of the from select
                $(this).val( $( fromSelector ).val() );
    
            }
    
        });
    
        // puts the gui in a valid state
        $( fromSelector ).change(function() {
    
            var fromSelector = "#" + $(this).attr( "id" );
            var toSelector = "#" + $(this).attr( "relatedTo" );
    
            // compares if the value of this field is less than the value of the "to" select
            if ( $(this).val() < $( toSelector ).val() ) {
    
                // if so, change the value of the "to" select
                $( toSelector ).val( $(this).val() );
    
            }
    
        });
    
    }
    
    validateSelects( "#from1", "#to1" );
    validateSelects( "#from2", "#to2" );
    

    jsFiddle: http://jsfiddle.net/davidbuzatto/YNL6R/

    Edit: I inserted a custom atribute in each select to denote the select that they are binded.

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

Sidebar

Related Questions

I have two select fields in a form. Every time one of these select
On the form, I have one select and two input fields. These elements are
I have a form with two text boxes, one select drop down and one
I have two form fields, field 1 is a select menu with different packages
I'm using mechanize and have a problem on one form... the form has two
I have a form with two collection_select fields, the first one is an easy
I have two separate fields with a drop-down list, one is for User and
I have a form in CakePHP that has two live-search text input. Each one
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have two select menus (#id1 and #id2) that, when validated as containing a

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.