passing javascript variable to php ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

The code below is aimed at passing the date in the yyyyMMdd format
from the javascript calendar in an html file to the php in a another
file which then searches a MySQL database.

For some reason the sendPhp is not working.  

I need to send  

target=frameright (as the results of the next.php search appear in the
right hand frame), and


Any ideas please?!



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<link rel="STYLESHEET" type="text/css"

 <script type="text/javascript" src="fcp_calendar.js"></script>
 <script type="text/javascript">
   window.onload = function() {
    cal = new _
    cal.onselect = function(date) {;  
    function dateToISO(date) {
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    if (month < 10) month = "0" + month;
    if (day < 10) day = "0" + day;
    return year + month + day;
newdate = dateToISO(date);  

// the 2 functions below are used to pass the javascript variable
//to the php file, next.php

  function xmlreq(){
   req = new XMLHttpRequest();
  }else if(window.ActiveXObject){
   req = new ActiveXObject("Microsoft.XMLHTTP");


  function sendPhp(url){
  var req = xmlreq();
  req.onreadystatechange = stateHandler;"GET", url, true);



Re: passing javascript variable to php ?

Geoff Cox wrote:

Quoted text here. Click to load it


A very quick look tells me you have a ' after the frameright.
You cannot pass ' like that in a URL, you should URL-encode it  
encode() in JS if memory serves me well.

And this is actually a JS question, not PHP related at all. :-)
Try comp.lang.javascript for such questions, they have a few gurus that can  
help you a lot better.

Erwin Moller

Quoted text here. Click to load it

Re: passing javascript variable to php ?

On Wed, 07 Mar 2007 16:39:31 +0100, Erwin Moller

Quoted text here. Click to load it


sorry - a typo - the ' should not be there.



Quoted text here. Click to load it

Site Timeline