orionlogic Posted August 28, 2008 Share Posted August 28, 2008 Hi all, I want some JavaScript function output in php function. Such as: $my_name = "<script language=\"javascript\">document.write(\"myName\");</script>"; echo "$my_name"; // Outputs : myName When i try to insert variable into some php function it gives error. Lets say my function outputs myName and my age... $name = myName($age, $my_name); And it doesnt work. When i look into logs, i see that it gets the line "<script langua..... rather than the output. How can i put that JavaScript string output as function parameter ? Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/ Share on other sites More sharing options...
webent Posted August 28, 2008 Share Posted August 28, 2008 Why not use php to pass the variables to javascript instead of trying to output javascript code? Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627745 Share on other sites More sharing options...
orionlogic Posted August 28, 2008 Author Share Posted August 28, 2008 i want to get some browser specific data from user. Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627746 Share on other sites More sharing options...
kenrbnsn Posted August 28, 2008 Share Posted August 28, 2008 You need to use AJAX techniques for that. Ken Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627761 Share on other sites More sharing options...
orionlogic Posted August 28, 2008 Author Share Posted August 28, 2008 You need to use AJAX techniques for that. Ken I may try that but there is something which i dont understand. The $my_name variable holds the output as String. When i try to echo, it outputs the string like 'John' . But when i put that variable into function it gets the script line. Is that because variable is just a pointer? Why not only getting the output ? Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627770 Share on other sites More sharing options...
kenrbnsn Posted August 28, 2008 Share Posted August 28, 2008 PHP runs before Javascript. All you are doing is outputing the Javascript, which then gets executed, and in your case puts the string on the screen -- it doesn't store it anywhere. Ken Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627773 Share on other sites More sharing options...
orionlogic Posted August 28, 2008 Author Share Posted August 28, 2008 hmm now i see... thanks all. Link to comment https://forums.phpfreaks.com/topic/121693-javascript-output-in-php-function-parameter/#findComment-627778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.