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

  • Home
  • SEARCH
  • 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 8368791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:28:19+00:00 2026-06-09T13:28:19+00:00

This script produce a drop down form where I can select the number of

  • 0

This script produce a drop down form where I can select the number of drop down fields that can be displayed. However I’m kind of stuck on that. My problem now is how to make default text field base on the value of the second drop down form? For example if I select ‘Ms.’ It will produce Two text field else it will just one text field.

jQuery

$(document).ready(function() {
    $('#bookinfo_adult').change(function() {
        var num = $('#bookinfo_adult').val();
        var i = 0;
        var html = '';
        for (i = 1; i <= num; i++) {
            html += '<br>' + i + '. <select name="gender4-' + i + '">' + '</' + 'option>' + '<option value=' + '"m">Mr. ' + '</option' + '>' + '<option value=' + '"f">' + 'Ms. ' + '</option' + '>' + '</select' + '></br>';
        }
        $('#list').html(html);
    });
});​

HTML

<select id="bookinfo_adult" name="bookinfo_adult">
       <option value="0">- SELECT -</option>
        <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>
        <option value="6">6</option>
    </select>
<div id="list"></div>
  • 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-09T13:28:20+00:00Added an answer on June 9, 2026 at 1:28 pm

    Not quite sure what you’re asking, but I guess you want to display input fields dynamically based on the current selection in your generated select elements?

    So how about this?

    HTML:

    <input type="text" id="bookinfo_adult">
    <div id="list"></div>
    

    CSS:

    #list input { display: none; }
    

    JS:

    $(document).ready(function() {
        $('#bookinfo_adult').change(function() {
            var num = $('#bookinfo_adult').val(), i = 0, html = '';
            for (i = 1; i <= num; i++) {
                html += '<div>' + i + '. \
                             <select name="gender4-'+i+'"><option/><option value="m">Mr.</option><option value="f">Ms.</option><select> \
                             <input type="text" class="ms"> <input type="text" class="mr">\
                         </div>';
            }
            $('#list').html(html);
        });
        $(document).on("change", "#list select", function(){
            var parent = $(this).closest("div");
            switch ($(this).val()) {
                case "m": parent.find(".mr").show(); parent.find(".ms").hide(); break;
                case "f": parent.find("input").show(); break;
                default: parent.find("input").hide(); break;
            }
        });
    });
    

    I just added two text fields (hidden with CSS at first) and wrapped every “line” of your dropdown in a div for easier selection. Then a onchange handler is created that works for all elements being added to the DOM in the future (once you could use jQuery.live() for that, but it’s deprecated as of version 1.7). The handler itself should be self-explanatory. 😉

    Working example: http://jsfiddle.net/DfXEE/

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

Sidebar

Related Questions

This script successfully generated the pdfs to a folder tmp/.... However the ZIP output
I have this script that run to fix my menu bar to the browser
This is a script to produce the dataset of a nested table: create table
Suppose that I have an ASP.NET page, where a customer can select a product
I have problem with python multithreaded Queues. I have this script, where producer take
This script saves the files as /home/name/main/all my files and stuff . I want
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The
This script works fine on single click but on double click it shows both
This script uses jsdom and jquery to get the value of an a tag's
For this script, it checks to see if the file is a microsoft words

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.