Hi...
i am now making a form for ordering book..the problem is, i want to add new texbox if the user want to make more than one order by clicking add button..and it can save in database..then it can calculate total price for all book that the user order...please help me..i need to finish up this form before this friday....:S

I have done what u want....
form.php

<html>
<head>
<title>Add text
</title>
</head>
<script type="text/javascript">
function add_field(a){
	
		// create a div element
		var div1 = document.createElement('div');
		// Get template data
		if(a==1){
		div1.innerHTML = document.getElementById('fieldtpl').innerHTML;
}
		// append to div, so that template data becomes part of document
		document.getElementById('addhere').appendChild(div1);

	
}
</script>
<?php
$i=0;
?>
<form method="post" action="formaction.php" enctype="multipart/form-data" >
    <div id="addhere">

q		<input type="text" name="upload[]" value="" size="30" ><br/>
&nbsp;&nbsp;	<input type="text" name="ans[]" value="" size="30" ><br/><br/>
</div>

&nbsp;&nbsp;&nbsp;<input type ="button" value="add more" onclick="add_field(1);">
<input type ="button" value="add textarea" onclick="add_field(2);">	
<input type="submit">

</form>
<!-- Template. This whole data will be added directly to working div above -->  
<div id="fieldtpl" style="display:none">
q		<input type="text" name="upload[]" value="" size="30" ><br/>
&nbsp;&nbsp;	<input type="text" name="ans[]" value="" size="30" ><br/><br/>

</div>
</body>

formactiom.php

<?php
$i=0;

foreach($_POST['upload'] as $value )
{echo "<table border='1'><tr><td>";
echo $i+1;
echo "</td><td>".$value."</td><td>".$_POST['ans'][$i]."</td></tr></table><br/>";
$i++;
}
?>

PS-If ur problem is solved mark the thread as solved and add reputation and if u have any query PM me i m always their to help others....

could you please explain about your code...i'm not very expert in php (my bad..)...and what is the function to create formaction.php? can code in formaction.php be join with code in form.php so that it will be just one page?
thanks and sorry for asking too many question.....

you can try show/hide the form as per user request. A link when click to show a form enable user to input quantity and hide when ignore. make ur life easier @@"

HTH, GL.

In case you wan the code @@"
or juz ignore if useless to you @@

<html>
<head>
	<title>Page with no title</title>
	<script language='javascript' type='text/javascript'>
		function toggle() {
			var ele = document.getElementById("qtyFm");
			var text = document.getElementById("displayQty");
			if(ele.style.display == "block") {
				ele.style.display = "none";
				text.innerHTML = "Add Quantity";
			}
			else {
				ele.style.display = "block";
				text.innerHTML = "Hide me if you dun like to see me...";
			}
		}
	</script>
</head>
<body>
	<a id='displayQty' href='javascript:toggle();'>Add Quantity!</a>
	<div id='qtyFm' style='display:none;'>
		<form method='post' action='wherever.php'>
			Quantity: <input type='text' name='qty'><input type='submit' value='Dun click me!'>
		</form>
	</div>
<body>
</html>

HTH, GLHF!

actually formaction.php that i made was to display result that i entered in the form's textbox.....

i've get the code to add textbox onclick...but when i click submit button, the data
from added textbox did not insert into database...and also there is error said:
Error: Unknown column 'Array' in 'field list'...what it mean???

in the formaction.php ....just change it ....
In the loop just add sql query and it will work fine...i did this a long ago and it was working fine....

can you please give me the code...i really can't think right now...

did this form can insert the data into database?may i have the code?thanks

ok...then i hope this code might work...although not tested now...

<?php
$con=mysql_connect("localhost","root")
or die ("coultnot connect");
mysql_select_db("test",$con)
or die("database not found");

$i=0;
 
foreach($_POST['upload'] as $value )
{echo "<table border='1'><tr><td>";
echo $i+1;
echo "</td><td>".$value."</td><td>".$_POST['ans'][$i]."</td></tr></table><br/>";
$i++;
mysql_query("INSERT INTO record values('".$value."','".$_POST['ans'][$i]."'");
}
?>

Hope that it will work fine and solve your problem...
And it is solved mark the thread as solved....

Dear friend,

After adding some textbox, can I remove the box as well?

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.