Store in php variable onclick()
Hey, i have a textbox and an image.... When the image is clicked, i need all the text in the textbox to be stored in a PHP session variable.
Is this possible?
i was going to do womething like this:
Code:
<script>
function assignvariable() {
var currentvalue = document.form1.message.value;
document.write("<?php $_SESSION['message'] = " + currentvalue);
}
</script>
Would someone mind telling me if this is the way to go about it??
Many thanks, BIOSTALL
Re: Store in php variable onclick()
Your onclick event is a client-side event. To set a session variable you'll need to go via the server reload the page.
Code:
<script>
function assignvariable() {
var currentvalue = document.form1.message.value;
window.href="the_same_page.php?message="+document.form1.message.value;
}
</script>
<?php $_SESSION['message'] = $_GET["message"]; ?>
hope this helps