-7

Possible Duplicate:
How to pass JS variable to php?

How can I pass value from Javascript code to PHP variables.

Say we have this:

aa = $("#amount").text($("#progressbar").progressbar("option", "value")+"%");

declared in the <script> tag of the Javascript, I want this to be fetch or called in the PHP code.

2

3 Answers 3

6

You need to use AJAX or a form to submit information to the server.

Sign up to request clarification or add additional context in comments.

Comments

2
$.ajax({ url: 'test.php',
     data: {action: 'aa'},
     type: 'POST',
     success: function(output) {
                         alert(output);
                    }
     });

Comments

2

JS is Client side , PHP is server side. So there is not a direct way to do the passing but you can do what you need to do by another method and AJAX is best option to it. Apart from this as an example, Following is the trick in which i am assiging screen width to my php varaible from javascript and I can echo its width by echo $width but actually the javascript code is being executing on echo and variable $width doesnot hold the value of screensize i.e in my case 1366 its actually hold the javascript code (<script> document.write(window.screen.width); </script>) thats being executed on echo .

$width = '<script> document.write(window.screen.width); </script>';
echo $width;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.