Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    getting data from dynamic fields

    Hello,

    I have a problem regarding getting values from dynamic textfields/checkboxes.

    Firstly,

    I have this JavaScipt which creates dynamic txtbxs/checkbx like this when they click "Add Stage" / "Remove Stage" buttons: http://oi51.tinypic.com/33mwua8.jpg

    Code:
    
    <script type="text/javascript">
    var currentTxtBx = 0;
    function addTxtBx(){
     
    
     if (currentTxtBx >= 15) {
    	 alert("You've reached the maximum number of stages.");
     }else{
     
      var txtBxHolder = document.getElementById('txtBoxHolder');
    
      var newTxtBx = document.createElement('input');
      
      var newTxtBx1 = document.createElement('input');
    	
    
      
      
      
      newTxtBx.type = 'text';
      newTxtBx.name = "stage";
      newTxtBx.value = 'stage'+(currentTxtBx+1);
      
      newTxtBx1.type = 'checkbox';
    
     
    
      currentTxtBx++;
      
      var allTxtBxs = document.getElementById('txtBoxHolder').getElementsByTagName('input');
      
    
     
      txtBxHolder.appendChild(newTxtBx);
      txtBxHolder.appendChild(newTxtBx1);
    
      
     }
    }
    
    function removeTxtBx(){
     var allTxtBxs = document.getElementById('txtBoxHolder').getElementsByTagName('input');
     var allTxtBxs1 = document.getElementById('txtBoxHolder').getElementsByTagName('input');
     
    
     if (allTxtBxs.length == 0){
      alert('There are no stages to remove.');
     } else {
      document.getElementById('txtBoxHolder').removeChild(allTxtBxs[allTxtBxs.length-1]);
      document.getElementById('txtBoxHolder').removeChild(allTxtBxs1[allTxtBxs1.length-1]);
      currentTxtBx = allTxtBxs.length;
     }
    }
    </script>
    
    ....
    
    <input type="button" value="Add stage" onclick="addTxtBx()"> 
    <input type="button" value="Remove stage" onclick="removeTxtBx()">

    Now the problem is getting PHP to get those dynamic values. I tried the formal $_POST['stage'] and of course didn't go through.


    any suggestion?


    Thanks in advance

    -aaron

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    101
    Thanks
    16
    Thanked 12 Times in 12 Posts
    You can use echo var_dump($_POST); to see what parameters are being sent through to PHP.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •