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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:58:03+00:00 2026-06-05T16:58:03+00:00

I have a form which has three inputs when the page loads — 2

  • 0

I have a form which has three inputs when the page loads — 2 select boxes and 1 text box.

I have created an AJAX call which will populate the second select box depending on what the user picked in the first select box. I also have a button which will append the very same input fields with unique names and ids to the form.

The problem I am having is trying to figure out which select box has been changed. As of now when the page loads I can select an option and populate the second select box but when I append another set of input fields and choose from the second select box it does not populate the corresponding select box.

If I select from the select box which is displayed when the page loads instead of populating its corresponding select box, it populates the newly appended select box.

Here is the code:

$(document).ready(function() {
var i = $('.clonedInput').length;
var count = 2;

$('#prescriptions'+i).change(function() {
    alert(i);
    var value = $(this).val();
    var dataString = 'prescription='+value;
    $.ajax ({
        type: 'POST',
        url: '<?php echo base_url(); ?>index.php/patients/dynamic_ddl',
        data: dataString,
        cache: false,
        success: function(html) { $('#dosage'+i).html(html); } 
    });
});

$(function(){ 
    $('#btnAdd').click(function(){          
        $('#page_properties').append('<tr id="input'+count+'" class="clonedInput">'+
                                '<td><label for="prescriptions'+count+'">Prescription</label></td>'+
                                '<td><select id="prescriptions'+count+'" class="prescriptions" name="prescriptions'+count+'">'+
                                '<option selected="selected">--Select Prescription--</option>'+
                                '<?php foreach ($prescriptions_sel as $option):?>'+
                                '<option value="<?php echo $option['prescription']; ?>"><?php echo $option['prescription'];?></option>'+
                                '<?php endforeach ?></select></td>'+
                                '<td>Dosage: <select id="dosage'+count+'" name="dosage'+count+'" class="dosage">'+
                                '<option selected="selected">--Select Dosage--</option>'+
                                '</select>'+
                                'Add Dosage: <input type="text" name="new_dosage'+count+'" value="" /></td></tr>');
        $('#btnDel').removeAttr('disabled');
        count++;
        i++;
    });
}); 


$('#btnDel').click(function() {                 
    var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have                 
    $('#input' + num).remove(); // remove the last element                   

    // enable the "add" button                 
    $('#btnAdd').removeAttr('disabled'); 

    // if only one element remains, disable the "remove" button                 
    if (num-1 == 1) $('#btnDel').attr('disabled','disabled'); 
    count--;
    i--;
});
$('#btnDel').attr('disabled','disabled');
});

I have been at this for hours, trying this with if statements, for statements, foreach statements (you name it).

  • 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-05T16:58:09+00:00Added an answer on June 5, 2026 at 4:58 pm

    Not quite sure if I’m following what you mean, but it sounds like your events only fire on items that exist when the document is ready, and not those items added dynamically.
    If so, and your problem is on your change function, the you need to use the live function to bind your events rather than the change function. i.e.

    $('#prescriptions'+i).change(function() {
    

    needs to be

    $('#prescriptions'+i).live('change', function() {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which has a Combo Box Control. I have selected the
I have a maximized form which has Combo-Box control (docked in top-right) with 500px
So I have a form that has 4 inputs, 2 text, 2 hidden. I've
I have a form-1 which has 4 fields. when the user inputs data in
I have a form on my PHP page which performs some ajax validation (that's
I have a page on which I am ajax-ing in a table which has
I have an ASP.NET page that has three div s within the only form
I have a form which has a collection for manager which is an autocomplete
I have a form which has a ListView and buttons to add/edit/delete items from
I have a form which has a drop down list for countries. If 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.