A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearAccess a javascript function value within PHP? - page 1
User InfoPosts
Access a javascript function value within PHP?#1
Can I access the value of a javascript function from outside the function
like if I had a function

function test_tree(opt)
val = opt;

Can I access the val value from outside the test_tree function or is there a way to access it from PHP code?

I need to be able to access a value from the javascript code in PHP code.

posted date: 2009-04-11 23:29:00

Re: Access a javascript function value within PHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-11 23:29:01

Re: Access a javascript function value within PHP?#3
Set the value to a hidden field, and read hidden field in your server side code.<input type="hidden" id="myVariable">In your function : document.getElementById((myVariable().value = val;

posted date: 2009-04-11 23:33:00

Re: Access a javascript function value within PHP?#4
Considering that you didn(t use var to declare the variable it is available to every function and all code in the global scope and beyond because without the var the variable is created in the global scope.Answering your question though, if you want the variables created inside a function to exist beyond the life of a function, use a closure. You could give the variable to some object accessible outside the function which has the job of storing a bunch of these values.If you want the variable (created in JavaScript and therefore I assume on the client) to be accessible to your PHP back end you(ll have to send a request to your server. Probably an ajax call if this execution isn(t part of submitting a form.

posted date: 2009-04-11 23:37:00

Re: Access a javascript function value within PHP?#5
possible duplicate of Pass a PHP string to a Javascript variable (including escaping newlines), How to pass a variable / data from javascript to php and vice versa? and many others (depending on exactly what jarus is asking for).

posted date: 2012-02-13 04:37:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.