NYCPHP Meetup

NYPHP.org

[nycphp-talk] Passing JAVASCRIPT variables to PHP

Kristina Anderson ka at kacomputerconsulting.com
Sat Apr 5 15:21:41 EDT 2008


You are passing your date variable into a querystring instead of into 
the form.  Therefore when you POST your form, the value is not there 
for the server side to read.  Also I don't believe you should use $ 
characters in your form field names, which in any event won't pass in 
the date value.

try something like this:

<input type="text" name="dateholder" value="<? echo $datum ?>" size=20>

Change the input type to "hidden" after you are seeing the date is 
populating in the form.

-- Kristina

> Sorry Mate,
> 
> I lost it. I just cannot see what I'm doing wrong. All the coding 
before 
> Datum is just working out the date. the following snippet is where I 
am 
> trying to upload the Javascript data to the server.
> 
> Paul
> 
> Datum = ( +Year+ '/' +Month+ '/' +Day+ ' - ' +Hours+ ':' 
+Minutes+ ':' 
> +Seconds);
> 
> var $datum = Datum;
> new Image()).src = 'http://www.localhost/showdatum.php?
$datum='+"$datum";
> 
> </SCRIPT>
> <FORM action="showdatum.php" method="post">
> <input type='text' name='$datum' size='20'><br>
> </FORM>
> </BODY>
> </HTML>
> 
> showdatum.php
> ===========
> <?PHP $datum = $_POST['$datum'];
> echo('$datum = ' . $datum . "<BR>"); ?>
> 
> 
> ----- Original Message ----- 
> From: "tedd" <tedd at sperling.com>
> To: "NYPHP Talk" <talk at lists.nyphp.org>
> Sent: Monday, March 31, 2008 2:27 PM
> Subject: Re: [nycphp-talk] Passing JAVASCRIPT variables to PHP
> 
> 
> > At 6:07 PM -0400 3/30/08, Daniel Convissor wrote:
> >>Hi Paul:
> >>
> >>On Sun, Mar 30, 2008 at 09:18:10PM +0100, PaulCheung wrote:
> >>
> >>>  The problem is I cannot transfer the Javascript variable needed 
in to 
> >>> PHP.
> >>
> >>JavaScript is client side.  PHP is server side.  This has been 
discussed
> >>on this list a couple times, and on the web too many times to count.
> >>
> >>You either need to submit the JS data to the server as part of a 
form or
> >>via an AJAX request.
> >>
> >>--Dan
> >
> >
> > --Dan:
> >
> > And don't forget this way:  :-)
> >
> > var a = 1;
> > (new Image()).src = '/myscript.php?a='+ a;
> >
> > Cheers,
> >
> > tedd
> >
> > -- 
> > -------
> > http://sperling.com  http://ancientstones.com  
http://earthstones.com
> > _______________________________________________
> > New York PHP Community Talk Mailing List
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
> > NYPHPCon 2006 Presentations Online
> > http://www.nyphpcon.com
> >
> > Show Your Participation in New York PHP
> > http://www.nyphp.org/show_participation.php 
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
\



More information about the talk mailing list