Jump to content

Php in javascript


Rochtus

Recommended Posts

Is it possible to put a little PHP code like this

 

<script type="text/javascript>

<?php

$tester = $_POST['test'];

?>

var helloworld = $tester;

document.write(helloworld);

</script>

 

kweet ni zeker of dit script werkt,

heb efkes snel geschreven

maar zou dit principe werken?

 

 

It doesn't work that way. In your case PHP is serverside(on a webserver) and javascript runs clientside(within your browser). If you want to see how your javascript looks like use the "view source" option in your browser.

 

It should be like this btw

<?php
$tester = $_POST['test'];
?>
<script type="text/javascript>
var helloworld = "<?php echo $tester; ?>";
document.write(helloworld);
</script>

 

Link to comment
https://forums.phpfreaks.com/topic/164836-php-in-javascript/#findComment-869199
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.