Forum Moderators: coopster
I have written a form which takes keywords, and returns them in another textarea with quotation marks on either side.
The problems I am facing are:
1. I am not able to get the Reset button to Blank out the two Text areas.
2. Ideally I would like to accomplish this within 1 form element only - containing both the text areas.
Please suggest what is wrong in this code. Thanks.
<body>
<table width="300" border="0" cellspacing="5" cellpadding="5">
<tr>
<td align="left">
<form name="a" method="POST" action="test1.php">
<?php
$outlist = $_POST['outlist'];
$text = str_replace("\r", "", $_POST['search']);//to process the windows new line
$arrtext = explode("\n", $text); // create array of keywords
echo "Key in one keyword in each row<br>";
echo "<textarea name=\"search\" cols=\"25\" rows=\"10\">$text</textarea>";
foreach($arrtext as $keyword)
{
$outlist = $outlist . '"' . $keyword . '"' . "<br>";
}
$outlist = str_replace("<br>", "\n", $outlist); //to process the windows new line
?>
</form></td>
<td align="center">
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset " />
</td>
<td>
Output List:
<?php
echo "<form>";
echo "<textarea name=\"outlist\" cols=\"25\" rows=\"10\">$outlist</textarea></form>";
?>
</td>
</tr>
</table>
</body>
<body>
<table width="300" border="0" cellspacing="5" cellpadding="5">
<tr>
<td align="left">
<form name="a" method="POST" action="test1.php">
<?php
$outlist = $_POST['outlist'];
$text = str_replace("\r", "", $_POST['search']);//to process the windows new line
$arrtext = explode("\n", $text); // create array of keywords
echo "Key in one keyword in each row<br>";
echo "<textarea name=\"search\" cols=\"25\" rows=\"10\">$text</textarea>";
foreach($arrtext as $keyword)
{
$outlist = $outlist . '"' . $keyword . '"' . "<br>";
}
$outlist = str_replace("<br>", "\n", $outlist); //to process the windows new line
?>
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset " />
</td>
<td>
Output List:
<?php
echo "<textarea name=\"outlist\" cols=\"25\" rows=\"10\">$outlist</textarea></form>";
?>
</td>
</tr>
</table>
</body>
here's the latest code now, and reset is still not working. Please help.
<body>
<table width="300" border="0" cellspacing="5" cellpadding="5">
<tr>
<form name="a" method="POST" action="test1.php">
<td align="left">
<?php
$outlist = $_POST['outlist'];
$text = str_replace("\r", "", $_POST['search']);//to process the windows new line
$arrtext = explode("\n", $text); // create array of keywords
echo "Key in one keyword in each row<br>";
echo "<textarea name=\"search\" cols=\"25\" rows=\"10\">$text</textarea>";
foreach($arrtext as $keyword)
{
$outlist = $outlist . '"' . $keyword . '"' . "<br>";
}
$outlist = str_replace("<br>", "\n", $outlist); //to process the windows new line
?>
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset " />
</td>
<td>
Output List:
<?php
echo "<textarea name=\"outlist\" cols=\"25\" rows=\"10\">$outlist</textarea>";
?>
</td></form>
</tr>
</table>
</body>
One solution could be to create a PHP-script that empties the variables when Reset is pressed. Something along the lines:
<?php
if($_POST["Reset"]) {
$outlist = "";
$text = "";
}
?>
I'm not sure how the reset button actually works (is it sent in POST?) and a quick Google did not reveal the answer so if this does not work, change the type of the Reset button to Submit and name it "Reset".
Hope this helps some.
<body>
<script>
function resetForm(){
document.forms[0].search.value = "";
document.forms[0].outlist.value= "";
}
</script>
<table width="300" border="0" cellspacing="5" cellpadding="5">
<tr>
<form name="a" method="POST" action="index.php">
<td align="left">
<?php
$outlist = $_POST['outlist'];
$text = str_replace("\r", "", $_POST['search']);//to process the windows new line
$arrtext = explode("\n", $text); // create array of keywords
echo "Key in one keyword in each row<br>";
echo "<textarea name=\"search\" cols=\"25\" rows=\"10\">$text</textarea>";
foreach($arrtext as $keyword)
{
$outlist = $outlist . '"' . $keyword . '"' . "<br>";
}
$outlist = str_replace("<br>", "\n", $outlist); //to process the windows new line
?>
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit" />
<input type="button" name="Reset" onclick="resetForm();" value="Reset " />
</td>
<td>
Output List:
<?php
echo "<textarea name=\"outlist\" cols=\"25\" rows=\"10\">$outlist</textarea>";
?>
</td></form>
</tr>
</table>
</body>