Results 1 to 2 of 2

Thread: Transfer JavaScript Variable To PHP Script

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    119

    Transfer JavaScript Variable To PHP Script

    Hello I need some help, I want to transfer information held in a javascript variable to a php variable, how can I achieve this? Is it possible?

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Transfer JavaScript Variable To PHP Script

    Code:
    <script language="javascript">
    var myVar = "Hello World";
    
    window.open("page.php?myVar=" + myVar);
    
    </script>
    You can pass them though Get, via the query string, or you can do something a little more complex and pass them though POST

    Code:
    <form id="article">
    <input type="hidden" value="" id="action"/>
    </form>
    <script language="javascript">
    var action = document.getElementById("action");
    	action.value = "previewarticle";
    	var frm = document.getElementById("article");
    	frm.target = "_NEW";
    	frm.action = "yourpage.php";
    	frm.submit();
    </script>
    There might be some better ways of doing this so if your still suck your best bet would be to ask the lovely people in XML, HTML, Javascript, Web and CGI

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