Learning & Integrating web technology and code help directory

How to use PHP & Multiple Input Text Field/Textbox

No comments
How to use PHP & Multiple Input Text Field/Textbox This tutorial how to using PHP read a variable frommultiple input textbox
ShotDev Focus:
- Using PHP & Multiple Textbox
Example 1
php_multiple_textbox1.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <form action="php_multiple_textbox2.php" method="post" name="form1">  
  7. <input type="text" name="txtSiteName[]"><br>  
  8. <input type="text" name="txtSiteName[]"><br>  
  9. <input type="text" name="txtSiteName[]"><br>  
  10. <input name="btnSubmit" type="submit" value="Submit">  
  11. </form>  
  12. </body>  
  13. </html>  
php_multiple_textbox2.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. for($i=0;$i<count($_POST["txtSiteName"]);$i++)  
  8. {  
  9. echo "txtSiteName $i = ".$_POST["txtSiteName"][$i]."<br>";  
  10. }  
  11. ?>  
  12. </body>  
  13. </html>  
  14.  
  15.  

Create a php file and save to path root-path/myphp/
Screenshot
PHP Multiple Textbox
PHP Multiple Textbox
.
.
Example 2 (Create Element)
php_multiple_textbox3.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. <script language="javascript">  
  5. function fncCreateElement(){  
  6.   
  7. var mySpan = document.getElementById('mySpan');  
  8.   
  9. var myElement1 = document.createElement('input');  
  10. myElement1.setAttribute('type',"text");  
  11. myElement1.setAttribute('name',"txtSiteName[]");  
  12. mySpan.appendChild(myElement1);  
  13.   
  14. var myElement2 = document.createElement('<br>');  
  15. mySpan.appendChild(myElement2);  
  16. }  
  17. </script>  
  18. </head>  
  19. <body>  
  20. <form action="php_multiple_textbox4.php" method="post" name="form1">  
  21. <input type="text" name="txtSiteName[]">  
  22. <input name="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"><br>  
  23. <span id="mySpan"></span>  
  24. <input name="btnSubmit" type="submit" value="Submit">  
  25. </form>  
  26. </body>  
  27. </html>  
php_multiple_textbox4.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. for($i=0;$i<count($_POST["txtSiteName"]);$i++)  
  8. {  
  9. echo "txtSiteName $i = ".$_POST["txtSiteName"][$i]."<br>";  
  10. }  
  11. ?>  
  12. </body>  
  13. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP Multiple Textbox
PHP Multiple Textbox
.
.



No comments :

Post a Comment