0

hi..

im dynamicelly creating text box in a html file using javascript..

<script>
function create_input_boxes()
{ 
if(document.getElementById("name0"))
{
	return true;
} 
var boxes=""; 
var num_boxes=document.getElementById("num_boxes").value; 
if(num_boxes) 
{  
	for(var i=0;i<num_boxes;i++)  
	{   
		boxes+="<input id='name"+i+"' name='name"+i+"' value=''><br />";   
	}  
	document.getElementById("textbox_container").innerHTML=boxes;  
} 
return false; 
}
</script>
</head>

<body>
<form id="theForm" action="dynamic.php" method="post" onsubmit="return create_input_boxes();">
<div id="textbox_container"></div>
Enter number input boxes: <input name="num_boxes"><br />
<div id="submit_button"><input type="submit" name="submit" value="Submit"></div>
</form>
</body>

while im trying to retrieve the values in php..

i get parse error in line 17. in my php file..

<html>
<head>

</head>
<body>
<?php

if(isset($_POST["submit"]))
{ 	
	for($i=0;$i<count($_POST);$i++) 
    {  
    	$name[]=!empty($_POST["name".$i])?$_POST["name".$i]:""; 
        // All dynamically created inputs are being stored again in $name array  
    } 
    for($i=0;$i<count($name);$i++) 
    (  
    	echo $name[$i];  
    } 
}
?>
</body>
</html>

plz help me in correcting the code.. Thank u

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by smvec
0

hi..

im dynamicelly creating text box in a html file using javascript..

<script>
function create_input_boxes()
{ 
if(document.getElementById("name0"))
{
	return true;
} 
var boxes=""; 
var num_boxes=document.getElementById("num_boxes").value; 
if(num_boxes) 
{  
	for(var i=0;i<num_boxes;i++)  
	{   
		boxes+="<input id='name"+i+"' name='name"+i+"' value=''><br />";   
	}  
	document.getElementById("textbox_container").innerHTML=boxes;  
} 
return false; 
}
</script>
</head>

<body>
<form id="theForm" action="dynamic.php" method="post" onsubmit="return create_input_boxes();">
<div id="textbox_container"></div>
Enter number input boxes: <input name="num_boxes"><br />
<div id="submit_button"><input type="submit" name="submit" value="Submit"></div>
</form>
</body>

while im trying to retrieve the values in php..

i get parse error in line 17. in my php file..

<html>
<head>

</head>
<body>
<?php

if(isset($_POST["submit"]))
{ 	
	for($i=0;$i<count($_POST);$i++) 
    {  
    	$name[]=!empty($_POST["name".$i])?$_POST["name".$i]:""; 
        // All dynamically created inputs are being stored again in $name array  
    } 
    for($i=0;$i<count($name);$i++) 
    (  
    	echo $name[$i];  
    } 
}
?>
</body>
</html>

plz help me in correcting the code.. Thank u

Check line 16 in your code '(' has to be "{ "

0

Apart from that you need to provide the Id to 'num_boxes' like

<?
if(isset($_POST["submit"]))
{ 	
	for($i=0;$i<count($_POST);$i++) 
    {  
    	$name[]=!empty($_POST["name".$i])?$_POST["name".$i]:""; 
        // All dynamically created inputs are being stored again in $name array  
    } 
    for($i=0;$i<count($name);$i++) 
    { 
    	echo $name[$i];  
    } 
}
?>
<html>
<head>
<script>
function create_input_boxes()
{ 
if(document.getElementById("name0"))
{
	return true;
} 
var boxes=""; 
var num_boxes=document.getElementById("num_boxes").value; 
if(num_boxes) 
{  
	for(var i=0;i<num_boxes;i++)  
	{   
		boxes+="<input id='name"+i+"' name='name"+i+"' value=''><br />";   
	}  
	document.getElementById("textbox_container").innerHTML=boxes;  
} 
return false; 
}
</script>
</head>

<body>
<form id="theForm" action="" method="post" onsubmit="return create_input_boxes();">
<div id="textbox_container"></div>
Enter number input boxes: <input type="text" id="num_boxes" name="num_boxes"><br />
<div id="submit_button"><input type="submit" name="submit" value="Submit"></div>
</form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.