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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:17:51+00:00 2026-06-11T23:17:51+00:00

This is my script I use to dynamically add/remove input text fields. I’m using

  • 0

This is my script I use to dynamically add/remove input text fields. I’m using the container properties so I can make multiple individual blocks for this input field.

$(function(){
    $('.container > a').click(function(e){
        e.preventDefault();
        var $this= $(this),
            prnt = $this.parent(),
            i = prnt.find('input').length;
        if($this.hasClass('add')){
            $('<div><input type="text" class="field" name="dynamic[]" value="' + i + '" /></div>').hide().fadeIn('slow').appendTo($('.inputs',prnt));
        }else if($this.hasClass('remove') && i > 1){
            prnt.find('input.field:last').remove();
        }else if($this.hasClass('reset') && i > 1){
            prnt.find('input.field:gt(0)').remove();
        }
    });
})

This is the html code I am using to build the input field:

<div class="container">
<a href="#" class="add">Add</a> | <a href="#" class="remove">Remove</a> | <a href="#" class="reset">reset</a>
    <div class="inputs">
        <input type="text" name="dynamic1" class="field"/>
    </div>
</div>

I need a PHP code to output all the fields from the input fields. If I add 3 input fields, I want the PHP code to output all of those input fields one after another.

I tried using the foreach code:

<?php
foreach($_POST['dynamic[]'] as $value) {
echo "$value <br />"; // change this to what you want to do with the data
}
?>

But I keep getting errors on the 2nd line (the foreach line)

How do I do this? Please help!

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

    You should change

    foreach($_POST['dynamic[]'] as $value) {
    

    To

    foreach($_POST['dynamic'] as $value) {
    

    Thats is if you have HTML like this

    <input type="text" name="dynamic[]" class="field"/>
    <input type="text" name="dynamic[]" class="field"/>
    

    But with your current HTML <input type="text" name="dynamic1" class="field"/> you can see that $_POST['dynamic'] is not a array you should just echo it like this

    echo $_POST['dynamic1'] ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use your example to dynamically add/remove editor and get this error:
I'm dynamically adding rows/fields in this code. I have a text field for the
I would like to use jQuery to dynamically add and remove sections of html
I need to dynamically add values from a text input to a listbox field.
I am using jQuery to dynamically add a script to my page and it
I want an app or python package that can 1.Dynamically add python script to
I use this script which submits links into a text file. The only problem
As with jQuery, you can use .load to dynamically load a file. I'm using
I use this script in two different servers: function curlGetFileInfo($url, $cookies=default){ global $_config; $ch
i use this script to load content of some div, inside another div: $(function()

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.