-1

Hi i'm begineer in PHP/JS and i have small question, how can PHP read values of variables in JavaScript?

i have this JS code where i have values

<script type="text/javascript">

function test(tag) 
{
var output = tag; 
<?php $tags ?> = output; //i tested, but not works
}
</script>

there's php read code

<?php
echo "$tags";
?>

i'm in end with this, Thanks for answers!

4
  • 1
    it won't , php will execute in web server and response will sends to browsers. you can use ajax functionality for this scienario Commented Jul 7, 2016 at 17:41
  • No, why you need it? Commented Jul 7, 2016 at 17:42
  • Outside of the function, try this: alert('<?php echo $tags; ?>'); and make sure it's outputting what it should. Commented Jul 7, 2016 at 17:43
  • @Naisapurushotham You can use PHP in JQuery if it's inline in the HTML rather than in its own file. Although, I wouldn't suggest people go this route. It's rather clunky and seems unnecessary. Commented Jul 7, 2016 at 17:47

1 Answer 1

2
<?php $tags ?> = output; //i tested, but not works

should be

<?php echo $tags ?> = output;
Sign up to request clarification or add additional context in comments.

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.