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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:09:16+00:00 2026-06-11T16:09:16+00:00

I have a foreach loop that outputs a form with content for each array

  • 0

I have a foreach loop that outputs a form with content for each array entry as per bellow.

$cartOutput .= '<td><form action="cart.php" method="post">
        <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" id="quantity" />
        <input name="adjustBtn' . $item_id . '" type="submit" value="change" id="adjustBtn" hidden="true" />
        <input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
        </form></td>';

As you can see the submit button has a unique assigned name for depending on the item.

In my jquery file i have the bellow.

$('#quantity').change(function(){
$("[name^=adjustBtn]").closest("form").submit();

});

This works on the first form on the page but any additional form does not auto submit on change, i believe the name^=adjustBtn entry is grabbing all of the different buttons but im just not sure how to tell it which one to submit etc.

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

    You seem to need

    $('[name="quantity"]').change(function(){
       $(this).closest("form").submit();
    });
    

    Your id doesn’t seem needed. And beware that you can’t have more than one element with a given id (problem with “quantity” and “adjustBtn” in your code).

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

Sidebar

Related Questions

I have a loop that enters each non-empty text field into a database: foreach
I have a For Each loop that is looping through an array of strings
I have a foreach loop that iterates over objects in an array. Currently, it
I have a php for each loop which outputs a form for every product
Right now I have a foreach loop that grabs the first link with an
in a ASP.NET application (MVC) I have a foreach loop that loops through a
I have a simple Parallel.Foreach loop that has about 1000 rows in the DataTable,
In PHP I can use a foreach loop such that I have access to
I have a datatable that I add to the chart in foreach loop as
I have a loop that can look like this: For Each article In artAll

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.