Re: [PHP] how i assign a js variable to a php variable
At 2:16 AM +0700 9/18/09, saeed ahmed wrote: hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? saeed: Considering that js is client-side and php is server-side, you need to pass the value via a communication mechanism between the two. Your choices are the standard GET/POST or ajax. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how i assign a js variable to a php variable
hello, You can also try using AJAX technology to communicate with the server side code that is your php :). Regards, Gautam Bhatia Punjab,India mail2gautambha...@gmail.com On Fri, 2009-09-18 at 02:16 +0700, saeed ahmed wrote: hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? -- Regards, Saeed Ahmed Rajshahi, Bangladesh Blog: http://saeed05.wordpress.com -- Follow Me Linkedin http://www.linkedin.com/in/sas05Twitterhttp://twitter.com/saeed05 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how i assign a js variable to a php variable
Or you can also do this way: on loading ?php [...] echo input type='hidden' name='myphpvar' id='myphpvar' value='.$myphpvar.'; [...] echo input type='button' name='mybutton' id='mybutton' onclick='javascript:recalculateValue();' value='Click Me!' ; [...] ? script type=text/javascript functino recalculateValue(){ var myText = document.getElementById(myphpvar); var myValue = myText.value; /* operations with myText */ myText.value = myRecalcValue; } /script once changed, you choose how to proceed, maybe executing any other js funcion that use new value of/for the input, maybe submit the form an take it from the request in the next page (in the server side, this time). basicly is use hidden inputs as a container for php variables, and transform through js. 2009/9/18 Gautam Bhatia mail2gautambha...@gmail.com hello, You can also try using AJAX technology to communicate with the server side code that is your php :). Regards, Gautam Bhatia Punjab,India mail2gautambha...@gmail.com On Fri, 2009-09-18 at 02:16 +0700, saeed ahmed wrote: hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? -- Regards, Saeed Ahmed Rajshahi, Bangladesh Blog: http://saeed05.wordpress.com -- Follow Me Linkedin http://www.linkedin.com/in/sas05Twitterhttp://twitter.com/saeed05 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] 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/javascriptvar 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
RE: [PHP] how i assign a js variable to a php variable
Actually, it's even more simple ... forgive me: echo 'script type=text/javascriptvar myPHPvar='.json_encode($myPHPvar).';/script'; that's pretty much it From: an_...@hotmail.com To: jonathan.desarro...@gmail.com; mail2gautambha...@gmail.com CC: saeed@gmail.com; php-general@lists.php.net Date: Fri, 18 Sep 2009 13:01:28 +0200 Subject: RE: [PHP] 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/javascriptvar 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
Re: [PHP] how i assign a js variable to a php variable
imagine you have an assoc. array that you encode with json and save in 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 pass this myPHPvar javascript var as an input in a form. if you want to change its value and maintein it, must to use an static var, and only can access to this values via javascript functions where 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 my), mantaninance of data in hidden input and using DOM for accessing it, allow an easiest dinamic treatment of data without reload a web page. Even more if using jQwey or Prototype. 2009/9/18 Andrea Giammarchi an_...@hotmail.com Actually, it's even more simple ... forgive me: echo 'script type=text/javascriptvar myPHPvar='.json_encode($myPHPvar).';/script'; that's pretty much it From: an_...@hotmail.com To: jonathan.desarro...@gmail.com; mail2gautambha...@gmail.com CC: saeed@gmail.com; php-general@lists.php.net Date: Fri, 18 Sep 2009 13:01:28 +0200 Subject: RE: [PHP] 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/javascriptvar 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
Re: [PHP] how i assign a js variable to a php variable
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_...@hotmail.com Actually, it's even more simple ... forgive me: echo 'script type=text/javascriptvar myPHPvar='.json_encode($myPHPvar).';/script'; that's pretty much it From: an_...@hotmail.com To: jonathan.desarro...@gmail.com; mail2gautambha...@gmail.com CC: saeed@gmail.com; php-general@lists.php.net Date: Fri, 18 Sep 2009 13:01:28 +0200 Subject: RE: [PHP] 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/javascriptvar 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
RE: [PHP] how i assign a js variable to a php variable
You can not pass this myPHPvar javascript var as an input in a form. if you want to change its value and maintein it, must to use an static var, and only can access to this values via javascript functions where an event is invoked (in case you want to read or write values) with all due respect, there is absolutely nothing you can do better or differently with an hidden input. I can send and manage a JS var the same way you do via input, except I do not need to search a node, get it, and put it back every time I need to modify that var. Remote scripting, JSONP, Ajax are ways to do it since ages. Persistence, if we are talking about refer the variable rather than recreate it, is something not possible with or without the input, 'cause as PHP serialize/unserialize session vars, in JS you can save the var in JSON format and recreate it for each page reload, unless you do not use ajax, but in that case we are talking about synchronization between a client/server mirrored variable status. If you use Ajax for the entire client session, you need to update the varialbe status only once on page unload and that's it. If you want to change a user status step by step you use localStorage, Gears, or other technologies, unless you do jnot want to overload the server with useless requests performed for each operation over the variable. Regards _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx
[PHP] how i assign a js variable to a php variable
hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? -- Regards, Saeed Ahmed Rajshahi, Bangladesh Blog: http://saeed05.wordpress.com -- Follow Me Linkedin http://www.linkedin.com/in/sas05Twitterhttp://twitter.com/saeed05
Re: [PHP] how i assign a js variable to a php variable
On Fri, 2009-09-18 at 02:16 +0700, saeed ahmed wrote: hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? -- Regards, Saeed Ahmed Rajshahi, Bangladesh Blog: http://saeed05.wordpress.com -- Follow Me Linkedin http://www.linkedin.com/in/sas05Twitterhttp://twitter.com/saeed05 You can't. Javascript is executed in the browser, PHP is executed on the server. What are you trying to achieve, as maybe there is a better way to do it. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] how i assign a js variable to a php variable
I have to disagree Ash, you can pass js variable values to PHP but only through a page load. Then you could use $_REQUEST, $_POST, $_GET to retrieve it. I have done this before. And I am sure Ash does it on daily basis, the problem is the used therm: I want to *assign* ... not pass, assign! I am quite sure that is what he meant, since I cannot count people reading ?php ? in the middle of the page thinking it can interact directly with nodes and javascript, and being a new one, I think Ash replied in the correct way. Regards _ Share your memories online with anyone you want. http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1
RE: [PHP] how i assign a js variable to a php variable
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Thursday, September 17, 2009 3:19 PM To: saeed ahmed Cc: php-general@lists.php.net Subject: Re: [PHP] how i assign a js variable to a php variable On Fri, 2009-09-18 at 02:16 +0700, saeed ahmed wrote: hello guys, i'm new here in this list. guys i need a help. i can't assign a js variable value to a php variable. how can i do this? -- Regards, Saeed Ahmed Rajshahi, Bangladesh Blog: http://saeed05.wordpress.com -- Follow Me Linkedin http://www.linkedin.com/in/sas05Twitterhttp://twitter.com/saeed05 You can't. Javascript is executed in the browser, PHP is executed on the server. What are you trying to achieve, as maybe there is a better way to do it. Thanks, Ash http://www.ashleysheridan.co.uk I have to disagree Ash, you can pass js variable values to PHP but only through a page load. Then you could use $_REQUEST, $_POST, $_GET to retrieve it. I have done this before. [HallMarc Websites] __ Information from ESET Smart Security, version of virus signature database 4434 (20090917) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how i assign a js variable to a php variable
On Sep 17, 2009, at 2:43 PM, Andrea Giammarchi wrote: I have to disagree Ash, you can pass js variable values to PHP but only through a page load. Then you could use $_REQUEST, $_POST, $_GET to retrieve it. I have done this before. And I am sure Ash does it on daily basis, the problem is the used therm: I want to *assign* ... not pass, assign! I am quite sure that is what he meant, since I cannot count people reading ?php ? in the middle of the page thinking it can interact directly with nodes and javascript, and being a new one, I think Ash replied in the correct way. Regards All true, and probably appropriate to clarify the relationship between php and js. However, if the goal is to pre-set something in php land so you don't have to pass it with your next page navigation, you could use ajax to to pass the value to a simple php script that in turn updates a php session variable, so that it is already set when you do your next real page load. You would still be calling a page technically, but your current displayed page would remain in place and php would have the value available on its next page load. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] how i assign a js variable to a php variable
I have to disagree Ash, you can pass js variable values to PHP but only through a page load. Then you could use $_REQUEST, $_POST, $_GET to retrieve it. I have done this before. And I am sure Ash does it on daily basis, the problem is the used therm: I want to *assign* ... not pass, assign! I am quite sure that is what he meant, since I cannot count people reading ?php ? in the middle of the page thinking it can interact directly with nodes and javascript, and being a new one, I think Ash replied in the correct way. Regards All true, and probably appropriate to clarify the relationship between php and js. However, if the goal is to pre-set something in php land so you don't have to pass it with your next page navigation, you could use ajax to to pass the value to a simple php script that in turn updates a php session variable, so that it is already set when you do your next real page load. You would still be calling a page technically, but your current displayed page would remain in place and php would have the value available on its next page load. Very true. I really didn't intend to dismiss everything you said Ash. I apologize for that. You were absolutely correct in your statement about not being able to directly assign the value of a javascript variable to a PHP variable. I just felt that your response would leave the reader to believe that that wasn't any way to pass the value at all. In my attempt to throw my two cents in I essentially did the same to your response. I'm afraid I left some thinking I was dismissing your entire statement. Sorry about that. Thank you, Marc Hall HallMarc Websites 610.446.3346 [HallMarc Websites] __ Information from ESET Smart Security, version of virus signature database 4435 (20090917) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php