0

I have a problem of passing data from one textarea to another textarea on another page. I’m using php POST function in order to retrieve data from the first page. Also, I have JavaScript inserting data into the textarea on the first page with the help of JSON and PHP talking to MySQL database. Inserting data into textarea from the database on the first page works.

When I click on the submit button on the first page, no data is passed to the second page. Many thanks for your help.

Page 1
-----------------------------------------------------------------------------------------
<form action="page2.php" method="post" id="role" name="roleForm">
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
  <label for="background"></label>
  <textarea name="background" cols="71" rows="10" id="backgroundtext">
</textarea></p>
</fieldset>
<br></br>
<p><input type="submit" name="Submit" value="Add role to job description" id="addjobdesc" /></p>
</form>


JavaScript file (part of the file)
---------------------------------------------------------------------------------------
function set_background (newValue)
{
    var field = document.roleForm.backgroundtext;
    field.value = newValue;
}



page2.php
-------------------------------------------------------------------------------------------
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
  <label for="background2"></label>
  <textarea name="background2" cols="71" rows="10" id="backgroundtext2" value="<?php echo $_POST["background"]; ?>"/>     
</textarea></p>
</fieldset>
<br></br>

2 Answers 2

0

You have to write the content of the textarea BETWEEN the tags, not into a value attribute:

<textarea name="background2" cols="71" rows="10" id="backgroundtext2">
<?php echo $_POST["background"]; ?></textarea>

Be aware that this code is extremly unsafe! If the $_POST["background"] contains HTML it will be brake down your html-code etc.

1
  • Many thanks for your answer.It works now!The issue has been solved.The reason why I wrote it in the value attribute is because I've seen examples with it being used in <input type="text"/>. Mar 18, 2011 at 20:35
0

Shouldn't it be:

<textarea name="background2" cols="71" rows="10" id="backgroundtext2">
<?php echo $_POST["background"];?>
</textarea>
4
  • Any suggestions on how I can correct it?The issue is with JavaScript but I don't know on how to integrate it into the $POST command. Mar 18, 2011 at 20:05
  • @Igor - If you want the $_POST["background"] to be in the textarea, just put it between the <textarea> tags. Or do you want to do something else?
    – Kit
    Mar 18, 2011 at 20:08
  • Don't worry about the issue.It has been solved by @strauberry below.But thanks for your time anyway. Mar 18, 2011 at 20:32
  • @Igor - No worries. I think it is a similar answer.
    – Kit
    Mar 18, 2011 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.