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

What parse error?

It will usually give you something to go by, e.g. 'expecting x' or 'unexpected x'

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 "{ "

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>

hi..

thank you Network18.. i got it now..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.