d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php Count Dynamically Added Forms > Need Advice
Add Reply New Topic New Poll
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Sep 16 2013 11:12am
Hello guys/gals,

I am currently working on a web application for work, and was wondering if anybody could offer a quick solution.

I am using a JQuery function that allows the users to dynamically add additional forms to an HTML file.
Each dynamically added form is assigned a unique ID. such as rdBullet1, rdBullet2, rdBullet3, etc. etc.
My JQuery function can be viewed below.


What I need help with is writing a PHP script that can check to see how many of these unique forms exists, then echo the value of the form for each unique form.

Use to I had a set number of forms and I created a php script that would check if the form was empty, if not it would echo the value of the form..
Example
Code
<?php if (!empty($_POST["rdBullet1"]))  {echo "<li>" .$_POST["rdBullet1"];} ?>


Currently, I'm trying the following code, however it's not working as intended. It might be because my php variable usage.

Code

<?php
        $bulletID = 1;
        while (isset($_POST["rdBullet$bulletID"])) {
         echo "<li>" .$_POST["rdBullet$bulletID"];
         $bulletID++;}
        ?>


JavaScript:
Code
<script type="text/javascript" charset="UTF-8">
  $(document).ready(function(){
  var nextBulletID = 0;
   
   $("#rdAddBullet").click(function () {
    var bulletID = ++nextBulletID;
    $("#addDesc").append('<tr><td><label>Bullet ' + bulletID + '</label></td><td><input type="text" name="rdBullet' + bulletID + '" id="rdBullet' + bulletID + '"></td></tr>')
   });
  });
 </script>


This post was edited by grievance on Sep 16 2013 11:34am
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Sep 16 2013 11:52am
I figured it out.. sorry guys. should've worked just a little longer before posting here for help.
For those of your curious the php code I needed was

Code
<?php
        $bulletID = 1;
        while (isset($_POST["rdBullet".$bulletID])) {
         echo "<li>" .$_POST["rdBullet".$bulletID];
         $bulletID++;}
        ?>
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll