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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:04:31+00:00 2026-06-09T07:04:31+00:00

I have a button which appends a drop down menu to the site, and

  • 0

I have a button which appends a drop down menu to the site, and within the drop down value attribute are numbers. I’m using an ajax function to run a math equation using the values from the drop down.. this is my code:

var data1 = $('#data1').val();
var data2 = $('#data2').val();
var data3 = $('#data3').val();


$.ajax({
  type: 'GET',
  url: 'ajaxcalc.php',
  data: {
    data1: data1,
    data2: data2,
    data3: data3
   },
  dataType: 'json',
  cache: false,
  success: function(data) { alert('yay!'); })
   });
  },
 });

//show dropdowns code
$('#data1').click(function() {
var $d = $('<select name="data1" id="data1"><option selected="selected" value="null">Choose your data!</option><option value="5">Option 1</option><option value="1">Option 2</option><option value="14">Option 3</option></select><br/>').fadeIn().delay(1000);
$('.data1').append($d);
});

//html button code for append data1 drop down
<button id="data1">Add Dropdown</button>

My problem comes in when people append 2 of the same drop downs with the same id and I can’t retrieve both variables… It only gets the first drop down value!

in my ajaxcalc.php file I have this to retrieve variables:

$data1 = $_GET['data1'];
$data2 = $_GET['data2'];

I’m trying to allow someone to append the data1 drop down twice and pick 2 different values but still pass those values to my ajaxcalc.php file through the .ajax() function! does anyone know how I can accomplish this?

  • 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-09T07:04:33+00:00Added an answer on June 9, 2026 at 7:04 am

    In your case you don’t have an id of “data2” or “data3”. You keep appending “data1”. When appending the dropdown, you need to increment the number with the id.

    //show dropdowns code
    var dropdownCount = 1;
    $('#data1').click(function() {
        var $d = $('<select name="data' + dropdownCount + '" id="' + dropdownCount + '"><option selected="selected"          value="null">Choose your data!</option><option value="5">Option 1</option><option value="1">Option 2</option><option value="14">Option 3</option></select><br/>').fadeIn().delay(1000);
        $('.data1').append($d);
    });
    

    Try using that code in place of your dropdown code.

    EDIT

    A better solution would be to use a class instead of ids. If each dropdown had a class you could select them all (no matter how many were added) and loop through them to get values.

    var dropdowns = $(".dropdowns");
    //Loop through them to get values and pass them to your ajax call
    

    EDIT2

    Here is a fiddle I through together showing how you can add multiple dropdowns and pass an array back to your PHP page rather than individual variables.

    http://jsfiddle.net/JtUuN/

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

Sidebar

Related Questions

I have a button which creates form elements on click . My addelement function
I have a button which opens a context menu with a list of various
Basically I have a drop down list which is populated with text and values
i have a button that runs an ajax get which takes a long time.
I have an append button which appends endlessly if you click it endlessly. Lets
I have a piece of jQuery code which appends an input button to the
I have button which post values of form to url but during post i
I have a button which on Click loads another activity, but before it loads
I have a button which needs to get created dynamically but the problem is
I have a button which is in update panel. When I click on button

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.