Forum Moderators: coopster

Message Too Old, No Replies

Adding incrementing values in a textarea

         

me_great

8:52 pm on Apr 19, 2008 (gmt 0)

10+ Year Member



Hi,

My query is:

There are 3 text boxes, and on the click of a push button, the values of these text boxes are concatenated and are displayed in a textarea. (I have achieved until this)

Now, after the 1st entry , I want to empty the text boxes and then enter the 2nd set of values, which will again be displayed as a 2nd entry in the textarea. and the process can go on (until 6 or 7 sets).

Can you please help me to achieve the 2nd paragraph. I am not able to apply any loop for this.

Thanks for your help.

elitebomber

6:19 pm on Apr 21, 2008 (gmt 0)

10+ Year Member



Here's a solution using session variables:

<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text Boxes</title>
</head>

<?php

$block = "";

if($_GET["submit"] == "t"){

$box1 = $_POST["textfield"];
$box2 = $_POST["textfield2"];
$box3 = $_POST["textfield3"];

if(!$_SESSION["block"]){

session_register("block");

$_SESSION["block"] = $box1." ".$box2." ".$box3;
$block = $_SESSION["block"];

}

else{

$_SESSION["block"] = $_SESSION["block"]."\n".$box1." ".$box2." ".$box3;
$block = $_SESSION["block"];

}

}

?>

<body>
<form id="form1" name="form1" method="post" action="test.php?submit=t">
<label>
<input type="text" name="textfield" id="textfield" />
</label>
<p>
<label>
<input type="text" name="textfield2" id="textfield2" />
</label>
</p>
<p>
<label>
<input type="text" name="textfield3" id="textfield3" />
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
</p>
</form>

<p>Display</p>
<p>
<label>
<textarea name="textarea" id="textarea" cols="45" rows="5"><?php echo $block ?></textarea>
</label>
</p>
</body>
</html>