SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Form question

  1. #1
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form question

    Can I POST a Javascript variable to a php page?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes. A simple way to do it is a hidden field:

    Code html4strict:
    <form name="form1" action="post" onsubmit="return process(this)">
      <input type="hidden" name="jsvar" />
      <input type="submit" />
    </form>
     
    <script type="text/javascript">
    var jsvar='test';
     
    function process(form){
      form.elements['jsvar'].value=jsvar;
      return true;
    }
    </script>
    Saul


Bookmarks

Posting Permissions

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