web 2.0

How to use PHP & Multiple Input Text Field/Textbox

How to use PHP & Multiple Input Text Field/Textbox This tutorial how to using PHP read a variable from multiple input textbox

ShotDev Focus:
- Using PHP & Multiple Textbox

Example 1

php_multiple_textbox1.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form action="php_multiple_textbox2.php" method="post" name="form1">
<input type="text" name="txtSiteName[]"><br>
<input type="text" name="txtSiteName[]"><br>
<input type="text" name="txtSiteName[]"><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>

php_multiple_textbox2.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
for($i=0;$i<count($_POST["txtSiteName"]);$i++)
{
echo "txtSiteName $i = ".$_POST["txtSiteName"][$i]."<br>";
}
?>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_multiple_textbox1.php

Screenshot

PHP Multiple Textbox

PHP Multiple Textbox
.
.

Example 2 (Create Element)

php_multiple_textbox3.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
<script language="javascript">
function fncCreateElement(){

var mySpan = document.getElementById('mySpan');

var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"text");
myElement1.setAttribute('name',"txtSiteName[]");
mySpan.appendChild(myElement1);

var myElement2 = document.createElement('<br>');
mySpan.appendChild(myElement2);
}
</script>
</head>
<body>
<form action="php_multiple_textbox4.php" method="post" name="form1">
<input type="text" name="txtSiteName[]">
<input name="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"><br>
<span id="mySpan"></span>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>

php_multiple_textbox4.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
for($i=0;$i<count($_POST["txtSiteName"]);$i++)
{
echo "txtSiteName $i = ".$_POST["txtSiteName"][$i]."<br>";
}
?>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_multiple_textbox4.php

Screenshot

PHP Multiple Textbox

PHP Multiple Textbox

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (3 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “How to use PHP & Multiple Input Text Field/Textbox”

  1. 2clients…

Leave a Reply

You must be logged in to post a comment.