Results 1 to 4 of 4

Thread: How to pass Jvascript Variables to PHP

  1. #1
    Join Date
    Sep 2005

    resolved How to pass Jvascript Variables to PHP

    Hi Every one.
    I finally figured a way to pass JavaScript variables to PHP.
    I takes 3 files.
    1. Setup file a PHP or HTML
    <script language="javascript">
    var1= 9;
    var2= 19;
    var3= 'time';
    <!-- now we are calling the sender script -->
    <script language="javascript" src="sendpar.js"></script>

    2. the "translation" file is a JavaScript FORM

    document.write('<form name="sendme" action="showpar.php" method="post"><input type="hidden" name="par1" ><input type="hidden" name="par2" ><input type="hidden" name="par3" >');
    sendme.par1.value = var1;
    sendme.par2.value = var2;
    sendme.par3.value = var3;
    document.sendme.submit() ;

    3. is the PHP "receiver file"
    just a simple file to show you all values:

    foreach($_POST as $key => $dat) {
    echo $key .'='. $dat ."\r\n";

    That is ALL.

    Good Luck!

  2. #2
    Join Date
    Nov 2008
    You could also sent the post request via AJAX without using the form or any other intermediate steps.

  3. #3
    Join Date
    Apr 2009
    Um, no offense, but that is probably the worst way to accomplish the task.

  4. #4
    Join Date
    Apr 2007
    If you're going to be negative about someone's efforts please give the reasons and if you can, suggest a better solution.

    Mindzai's suggestion is a good one and allows for sending the jS vars to PHP without a page reload.

    Lazer, jQuery is a pretty easy way use AJAX. I've used Xajax for a while and like that too.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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