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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:51:25+00:00 2026-06-07T12:51:25+00:00

I am trying to grab the values of an array from html using jQuery

  • 0

I am trying to grab the values of an array from html using jQuery and then pass this over to a PHP script. I have tried many variations that I have found on this site, however none have been successful.

This is what I have so far. (I am using jQuery to generate the textareas depending on the required amount, up to a max of 10).

<form>
<input type='text' value='Title', name='title' id='title' /><br>
<h2 class="achievements" id="subheading">Required Amount</h2><br><br><br>
<select id="selection">
<option value='0'>0</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>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
<div class="achievements" id="board"></div>
</form>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#selection').change(function() {
    var required = parseInt($(this).val());
    var i = 0;
    var str1 = "<h2 id=\"subheading\">Requirements</h2><br><br><br>";

    for( i = 0; i < required; i++) {
                str1 += "<br><br><label></label><textarea name='requirement["+ i +"]' class=\"requirements\" rows='2' cols='40'></textarea>";
            }
    str1 += "<br><input type='button' class='button' onclick=\"button('achievements/create_achievement');\" value='Add Achievement'/>";
    $('#board').html(str1); 
});
return false;
});
</script>

The jQuery script that grabs the data is:

function button(uri) {
var url = "http://www.blahblah.com/" + uri;
    var requirements = [];
    /**
      * solution below found on SO does not work as thought
      */
    /////////////////////////////////////////////////////////////////////////
    requirements = $('textarea[name^="requirement\\[\\]"]').map(function() {
    return $(this).val();
    }).get();
    //////////////////////////////////////////////////////////////////////// 
    $.ajax({
    url: url,
    data: {id:requirements},
    type: "POST",
    success: function(data) {
        $('#main-board').html(data);
    }
    });
return false;
} 

My issue is that when checking for the array of data using alert(requirements) nothing is found. I assume this is because the data from the html is not being parsed correctly using the jQuery statement I have used. Any assistance would be great. Thanks

  • 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-07T12:51:26+00:00Added an answer on June 7, 2026 at 12:51 pm

    Your selector for the textareas are wrong, because the names of the textarea have a decimal in the brackets; also see the jquery selectors page for ^=:

    Description: Selects elements that have the specified attribute with a value beginning exactly with a given string.

    Replace

    $('textarea[name^="requirement\\[\\]"]')
    

    with

    $('textarea[name^="requirement\\["]')
    

    You don’t have to change anymore.

    Also see this exmaple.

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

Sidebar

Related Questions

I have this xml from which I am trying to grab the value in
Trying to grab the two $ values and the X value from this string
I have been trying to grab a file from an alternate git branch and
I'm trying to add the ID's, which are the $hexcode values from the html
I am trying to compare 2 values from 2 arrays, 1 array is from
I'm trying to grab the value of an array that I got from parsing
I am trying to grab the rgb values from 3 editboxes so that I
I am trying to figure out how to grab a value from Expression.Blend.SampleData. If
Im trying to grab the destination (dynamic) of a link (static) with php Im
Here is my javascript. I am trying to have jQuery send my sign in

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.