I'm fairly new to PHP and JavaScript, so I was wondering if it was possible to use info taken from a .php into a JavaScript variable and use it outside of the script itself. Here is the particular case I'm tackling right now:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LaWeaaa</title>
<link rel="stylesheet" type="text/css" href="assets/css/login.css">
</head>
<body>
<script type="text/javascript" src = pru.php>
var img = '<?php echo $imagenes;?>'
</script>
</body>
</html>
As it goes, I'd like to know if it is possible to use the variable 'img' outside of the script and if so, how to do it properly.
outside of the script? Since it's echoed into the<script>, you can have the Javascript use it as desired, including for manipulating HTMLsrc = pru.phpwon't work. May we see that file (or a sample of it) in your question? Does it just contain data or does it run code (and set variables)?<script type='text/javascript' src='myPhpFile.php'></script>where myPhpFile.php can use whatever variables and output them however you want, and then return a valid JavaScript file to process when your HTML file is loaded in the browser.