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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:29+00:00 2026-05-13T15:47:29+00:00

I am working on a new system and am stuck at a point with

  • 0

I am working on a new system and am stuck at a point with jquery + ajax and getting it work work correctly with the other things happening on the page.

Basically the page is to submit a quote and on the page you can add as many quote items as you want. When someone clicks on new item it runs the below code wich gets the value of a hidden element and uses it in all of the new elements Ids in order to keep them all unique.

New Product code:

    function addFormField() {
        var id = document.getElementById("field_id").value;
        $("#products").append("
<table width='600' cellpadding='5' cellspacing='0' class='Add_Products' id='row" + id + "'>
    <td width='250' class='left'>
      <label>Select Product Category</label>
    </td>
    <td class='right' >
      <label><select name='ProductCategory' id='ProductCategory'>
      <?php foreach($categories as $key=>$category){ 
                echo "<option value=".$key.">".$category."</option>"; 
            } 
             ?>
       </select>
      </label>
    </td>
  </tr>
  <tr>
     <td width='250' class='left'>
        <label>Select Product Template</label>
     </td>
     <td class='right' >
         <label>
         <select name='data[QuoteItem][" + id + "][product_id]' id='QuoteItem" + id + "product_id'></select>
          </label>
     </td>
   </tr>
   <tr >
     <td class='left'>Name</td>
     <td class='right'>
          <label>
             <input name='data[QuoteItem][" + id + "][name]' type='text' id='QuoteItem" + id + "name' size='50' />
          </label>
      </td>
    </tr>
     <tr >
       <td class='left'>
           Price (ex GST)
       </td>
       <td class='right'>
           <input type='text' name='data[QuoteItem][" + id + "][price]' id='QuoteItem" + id + "price' onchange='totalProductPrice();' class='quote-item-price' />
       </td>
    </tr>
    <tr>
       <td class='left'>
           Description
       </td>
       <td class='right'>
          <label>
                <textarea name='data[QuoteItem][" + id + "][description]' cols='38' rows='5' id='QuoteItem" + id + "description'>
                </textarea>
           </label>
         </td>
      </tr>
      <tr>
         <td>
           <a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'>Remove</a>
         </td>
      </tr>
  </table>
");


        $('#row' + id).highlightFade({
            speed:1000
        });

        id = (id - 1) + 2;
        document.getElementById("field_id").value = id;
    }

The next thing i want to do is setup an AJAX query using jQuery that when selected will request the appropriate data and populate the products box but i cannot figure out how to get the ID of that set of elements to ensure that the correct dropdown box is populated and also to make sure that the onchange is detected for the correct box.

Ive tried methods like adding the ID to the id of the dropdown box but then the onchagne doesnt work.

My jquery ajax code is below that retreives the list of products

    $(function(){
      $("select#ProductCategory").change(function(){
        var url = "productList/" + $(this).val() + "";
        var id = $("select#ProductCategory").attr('name');
        $.getJSON(url,{id: $(this).val(), ajax: 'true'}, function(j){
          var options = '';
        options += '<option value="0">None</option>';
          $.each(j, function(key, value){
        options += '<option value="' + key + '">' + value + '</option>';
          })
          $("select#QuoteItem" + id + "product_id").html(options);
        })
      })
    })  

For the life on my cannot figure this out so if anyone could shed some light on the best way to do it that would be great.

ALso if i need to clarify further let me know because im strugling to explain it.

Thanks in advance

  • 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-13T15:47:30+00:00Added an answer on May 13, 2026 at 3:47 pm

    I have similar functionality in my project. Here how I do it:

    I have a global variable that start with 0, and increased every time new field added:

    var num = 0;
    
    jQuery(function($){
      $("#add_field").click(function(){
        num++;
        //here add new field, with id contains 'num'
      });
    });
    

    to make it easier to debug, you should start with a simple element, test it so it’s bug free, and add more field to it.

    To submit form via AJAX, use jQuery form plugins, so you don’t need to add all fields manually in ajax code that submit the form.

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

Sidebar

Related Questions

I am working on a new system and am stuck at a point with
Currently, I am working on a new version control system as part of a
I am working in a new part of an existing system. What are the
I'm new to AS3 and have been working on an XML driven navigation system
I'm working on migration of data from a legacy system into our new app(running
When working on developing new software i normally get stuck with the redundancy vs
I'm still working on a Data Acquisition program in MFC and am getting stuck
Working on joining up two legacy DB systems into new database where I can
In the course of my career I've noticed that developers working on new functionality
In Git I can do this: 1. Start working on new feature: $ git

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.