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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:25:23+00:00 2026-06-11T02:25:23+00:00

I am writing a simple webpage which has two dropdown list with ages, say

  • 0

I am writing a simple webpage which has two dropdown list with ages, say both of them contains options from 1 to 30. I want dropdown 2 to change to the value user selected for dropdown 1. For example, in the first place, the two dropdowns are all having 1-30 as values and defaults are both 1. An user chooses 12 from the first dropdown, I want the second one to automatically change to 13.

So I figured this javascript snippet out,

    <script>
    $(document).ready(function(){
        $("#selectfromage").change(function(){
            var fromage=$("#selectfromage").val();
            $("#selecttoage").val(fromage);
            alert(fromage);
        });
    });
</script>

But the behavior is kinda weird, if I select a value from dropdown1, the alert fires but the .val does not. But if I refresh the page, dropdown 2 changes to the value in dropdown 1 automatically.

Please help.

Here is the snippet in my php source

<select name="fromage" id="selectfromage" data-inline="true" data-mini="true">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
        </select>
<script>
        $("#selectfromage").change(function(){
            var fromage=$("#selectfromage").val();
            $("#selecttoage").val(fromage);
        });
</script>
<select name="toage" id="selecttoage" data-inline="true" data-mini="true">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
        </select>
  • 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-11T02:25:25+00:00Added an answer on June 11, 2026 at 2:25 am

    This is how you can select second drop value one greater then the first.

    Live Demo

    $("#selectfromage").change(function() {
        var fromage = $("#selectfromage").val();
        alert($("#selecttoage option").length);
        if (+fromage < $("#selecttoage option").length)
            $("#selecttoage").val(+fromage + 1);
        else 
            $("#selecttoage").val(fromage);
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I writing a simple method which should delete an entity from the database if
I am writing a simple chrome extension which should replace the particular content of
I'm writing a webpage that has a table with rows that slide open and
I'm writing a pretty simple database application, which I want to be locally stored
I'm writing fairly simple application which connects to server through SSH (using paramiko ),
I'm writing a simple Python CGI script that grabs a webpage and displays the
I am writing simple parallel program in C++ using OpenMP. I am working on
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()
I am writing simple site that requires users and profiles to be handled. The

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.