And of course, sorry for my english!!! I correct!! Imagine you have an assoc. array that you encode with json and save into the > js var. Ok. > > This way is perfect. But you can do less with this values than using my > solution. Important: Each case is different, and may be studied in > particular. > > You can not send by request this myPHPvar javascript var as an input in a > form. if you want to change its value and maintain it, must to use an static > var, and only can access to this value via javascript functions when an > event is invoked (in case you want to read or write values) > > And I repeat: My solution is not the best, of course, but in many cases > (for me), data maintainance in hidden inputs, and using DOM to access it, > allow an easiest dinamic treatment of data without reloading a web page. > Even more if you are using jQwey or Prototype. > > > > 2009/9/18 Andrea Giammarchi <an_red@xxxxxxxxxxx> > > Actually, it's even more simple ... forgive me: >> >> echo '<script type="text/javascript">var >> myPHPvar='.json_encode($myPHPvar).';</script>'; >> >> that's pretty much it >> >> > From: an_red@xxxxxxxxxxx >> > To: jonathan.desarrollo@xxxxxxxxx; mail2gautambhatia@xxxxxxxxx >> > CC: saeed.sas@xxxxxxxxx; php-general@xxxxxxxxxxxxx >> > Date: Fri, 18 Sep 2009 13:01:28 +0200 >> > Subject: RE: how i assign a js variable to a php variable >> > >> > >> > >> > > basicly is use hidden inputs as a container for php variables, and >> transform >> > > through js. >> > >> > really? I though the other way round was extremely simple: >> > >> > echo '<script type="text/javascript">var >> myPHPvar=eval("('.addslashes(json_encode($myPHPvar)).')");</script>'; >> > >> > why would you use hidden input, plus DOM to get data, etc, etc? >> > >> > _________________________________________________________________ >> > Show them the way! Add maps and directions to your party invites. >> > http://www.microsoft.com/windows/windowslive/products/events.aspx >> >> ------------------------------ >> With Windows Live, you can organize, edit, and share your photos.<http://www.microsoft.com/middleeast/windows/windowslive/products/photo-gallery-edit.aspx> >> > >