Results 1 to 2 of 2

Thread: Store in php variable onclick()

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    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

  2. #2
    New Member
    Join Date
    Jul 2005
    Posts
    3

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width