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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:17:35+00:00 2026-05-29T09:17:35+00:00

I have a simple PHP script with a form that has two select fields,

  • 0

I have a simple PHP script with a form that has two select fields, both of which are simply numerical values. The script also has a maximum for the sum of the two fields. I’m trying to dynamically filter the second drop down, so that a user cannot select more than the maximum. E.g., if my maximum is 10, the first select dropdown would have 1-10 in it. A user selecting 6 would then only be able to select 0-4 in the second select dropdown.

I know this should be reasonably straightforward, but I’m a total JavaScript/jQuery novice. I have searched SO and Google, but I don’t understand enough of the examples I’ve seen to know where to start, let alone figure out how to customise them to my needs. I’ve provided the code I have already, which clearly doesn’t have any of the filtering I need.

Some sample code (assume $maximum defined already):

<script type="text/javascript">
    var max = <?php echo $maximum; ?>;
</script>

<select name="dropdown1" id="dropdown1">
<?php
for ($i = 1; $i <= $maximum; $i++)
{   
    echo '<option value="'.$i.'">'.$i.'</option>';  
}
?>
</select>
<select name="dropdown2" id="dropdown2">
<?php
for ($i = 0; $i <= $maximum; $i++)
{   
    echo '<option value="'.$i.'">'.$i.'</option>';  
}
?>
</select>

Thanks in advance.

I now have the following piece of jquery in it’s own .js file:

$(document).ready(function() {
// var max ??
$("#dropdown1").change(function() {
    var selectedVal = $(this).find("option:selected").val();
    $("#dropdown2 option").removeAttr("disabled").removeAttr("selected");
    $("#dropdown2 option").each(function() {
        if($(this).val() > max - selectedVal*1)
            $(this).attr("disabled", "disabled");

    });       
});
});

However, I’m a bit stuck getting $maximum from my PHP script into the jQuery. I figure I have to create a JavaScript variable, but not quite sure how to pass it to the jQuery. I can figure out how to do it if I had the jQuery embedded in the same PHP script, just by echoing it out, but not quite so sure about passing it as a parameter.

  • 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-29T09:17:36+00:00Added an answer on May 29, 2026 at 9:17 am

    I update code of legendofawesomeness for your case

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

Sidebar

Related Questions

I have a simple PHP mailer script that takes values from a form submitted
I have a simple contact form on a website that has 2 text fields,
I have a simple php script on a server that's using fsockopen to connect
I have a simple php script on my domain that sends me an email:
I have a simple PHP script that will either serve up a streaming ASF
I have a simple PHP script that sends a message to a specified email
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have an extremely simple script with PHP exec , calling mysql command: $dbhost
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php
I have written a very very very simple!! script in php. header redirection not

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.