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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:41:13+00:00 2026-05-30T00:41:13+00:00

I have a simple form for a hotel accommodation tool. User selects the number

  • 0

I have a simple form for a hotel accommodation tool. User selects the number of adults and children from dropdown boxes and the form then lets the user select the ages of children from newly generated dropdown boxes.

I can show and hide the select boxes. However, once a select box is shown, its value is posted no matter if it’s later hidden or not. I need to clear or reset the values of select boxes which are no longer displayed.

Here is my jquery:

    $(document).ready(function(){
$("#selectchild").change(function(){

    switch ($(this).val())
    {
      case "0":
        $("#hidechild1").slideUp("fast");
        $("#hidechild2").slideUp("fast");
        break;  
      case "1":
        $("#hidechild1").slideDown("fast");
        $("#hidechild2").slideUp("fast");
        break;
      case "2":
        $("#hidechild1").slideDown("fast");
        $("#hidechild2").slideDown("fast");
        break;
}           
    });
});

And here is my HTML:

<form id="ExampleForm" method="post" action="results.php">
<fieldset>
    <legend>Accommodation details. Please choose number of adults and children</legend>     
    <div class="input select">
        <label for="selectadult">Adult (>12)</label>
        <select name="selectadult" id="selectadult">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>                            
        </select>
    </div>

    <div class="input select">
        <label for="selectchild">Children (0-12)</label>
        <select name="selectchild" id="selectchild">
            <option value="0">0</option>
            <option value="1">1</option>
            <option value="2">2</option>                    
        </select>
    </div>      

    <div class="hide" id="hidechild1">
        <br/>Please specify the ages of children:
        <div class="input select">
            <label for="selectchild1">Child 1:</label>
            <select name="selectchild1" id="selectchild1">
            <option value="none">-?-</option>
            <option value="<1"><1</option>
            <? for ($i=1;$i<=12;$i++) { echo "<option value=\"$i\">$i</option>"; } ?>
            </select>
        </div>
    </div>

    <div class="hide" id="hidechild2">
        <div class="input select">
            <label for="selectchild2">Child 2:</label>
            <select name="selectchild2" id="selectchild2">
            <option value="none">-?-</option>
            <option value="<1"><1</option>              
            <? for ($i=1;$i<=12;$i++) { echo "<option value=\"$i\">$i</option>"; } ?>
            </select>
        </div>
    </div>      

</fieldset>
<div class="submit">
    <input type="submit" value="Submit!" />
</div>
</form>
  • 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-30T00:41:15+00:00Added an answer on May 30, 2026 at 12:41 am

    Try this:

    switch ($(this).val()) {
        case "0":
            $("#hidechild1").slideUp("fast");
            $("#hidechild2").slideUp("fast");
            resetFields("#hidechild1");
            resetFields("#hidechild2");
            break;  
        case "1":
            $("#hidechild1").slideDown("fast");
            $("#hidechild2").slideUp("fast");
            resetFields("#hidechild2");
            break;
        case "2":
            $("#hidechild1").slideDown("fast");
            $("#hidechild2").slideDown("fast");
            break;
    }    
    
    function resetFields(id) {
        $("select", id).val("none");
        // add other fields in here to reset, if needed.
    }
    

    This could be made prettier if you turned that function into a basic plugin, so you could call $("#hidechild1").slideUp("fast").resetFields(), but the above will at least work for you.

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

Sidebar

Related Questions

I have a simple form on a view page, implemented as a user control,
I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde
I have a simple form for searching for a user <p>Enter a user's id
I have simple registration form. Once all information entered, user click submit button and
I have a simple form that uses jQuery validation to notify the user of
I have a simple form containing a main view and also some text boxes
i have a simple form to validate if an user exists in the db,
I have a simple form, with a table (from the standard toolbox - 3
I have a simple form that lists user names and for each user, the
I have simple form. It contains few texboxes and one dropdown list. And I

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.