Hello, I'm into PHP/Javascript and having some problem here, so just want to seek help from you guys.
I have created a page with a textarea. (named Step 1) when the user clicked the "Next" <a></a> link the textarea's value will be stored in a session variable. I've did it by creating a separate php file and link the href value of the <a></a>, here is the php file's src.
<?php
session_start();
$_SESSION['var_gift_message'] = $_POST['gift_message'];
/* Remember header() must be called before any actual output is sent */
/* Redirect browser */
header("Location: http://mywebsite.com/step-3/");
/* For good order don't risk the code below the redirect
to be executed when we redirect. */
exit;
?>
(Don't mind the website address in the code, I've changed it, it's not the real website address...)
After storing the value of the textarea, the php page will redirect the user into a page with other stuffs
(named Step 2)...with a "Next" <a></a> link also. When the user clicked it, a new page will load with a textarea (Step 3)...now, what i need is to get the value of the session variable and insert it in the Step 3's textarea
Here is what i've coded so far: (TextArea_setText.js) -> this script is linked in Step 3's page.
window.onload = function( ) {
justpass( "<?php echo $_SESSION['var_gift_message'] ?>" );
}
function justpass(str) {
document.getElementById("my_field_name").value = str;
}
This works fine, but the problem is, the whole "<?php echo $_SESSION['var_gift_message'] ?>" is getting printed on the textarea, not the actual value of $_SESSION['var_gift_message']. I've tried to use single quotes but google chrome's developer tool raises an Error: Uncaught SyntaxError: Unexpected identifier
Then when I removed both quotes it raises an Error: **Uncaught SyntaxError: Unexpected token < **
Is it wrong that i've wrote it in .js and not in .php? or is there any other way?
I don't know if this is the correct way of doing it, because i'm still just starting to delve in PHP and Javascript. So i really have no idea, I'm just searching in google for examples.
By the way, I'm using Wordpress, and the textarea is auto-generated by a wordpress plugin (named WooCommerce). so i'm just depending on the textarea's ID. and i just can't insert the js function call ( justpass( str ) ) in the <textarea> element, because i cannot find it in the plugin's php pages...I've tried to read their documentation, but it didn't helped a lot.
Thank you in advance.