By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

Getting elements with same name

P: 24
I am creating a dynamic form in which you can add elements with javascript. This works fine.

Every time I click add new element >

I.E.
Expand|Select|Wrap|Line Numbers
  1. cell_3.innerHTML = "<select name='team_A' id='team_A"+lastRow+"'></select>"; 
  2.  
With Dom I can access all elements with name team_A like this team_A[0] ,team_A[1] and so on later.

However can I access every element through $_GET[team_A[0]] or $_POST command or will I have to name every element seperately.

Hope you can understand what I am on about.
Jul 24 '07 #1
Share this Question
Share on Google+
1 Reply


ilearneditonline
Expert 100+
P: 130
I am creating a dynamic form in which you can add elements with javascript. This works fine.

However can I access every element through $_GET[team_A[0]] or $_POST command or will I have to name every element seperately.
Hope this helps. Probably not exactly what you were looking for but may help u get started.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST["submitform"]))
  3. {
  4.     foreach($_POST['myselect'] as $key => $value)
  5.     {
  6.         // do something
  7.     }
  8. }
  9. ?>
  10.  
  11. <form action="testform.php" method="POST">
  12. <select name="myselect[]">
  13.     <option value="MD">Maryland
  14.     <option value="PA">Pennsylvania
  15. </select>
  16.  
  17. <select name="myselect[]">
  18.     <option value="US">United States
  19.     <option value="UK">United Kingdom
  20. </select>
  21.  
  22. <input type="submit" value="submitform" name="submitform" />
  23. </form>
Jul 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.