Hello everyone,
The following HTML/JavaScript code inserts a background imag to a div without causing problems.
I need to run that JS script from a PHP code so I wrote:
With the second code I was less lucky/ This time the desired background image didn't show up, probably, because
I dont know how to run JS code from PHP.
Could anyone help me with that please?
Thanks
The following HTML/JavaScript code inserts a background imag to a div without causing problems.
Code:
<!DOCTYPE html>
<html lang = "en">
<head>
<title>to-forum.html</title>
<script>
function ChangeImage(param)
{
return("[URL unfurl="true"]http://localhost/images/greensilver.gif");[/URL]
}
</script>
</head>
<body>
<div id="logo" style = "height:400px; width:400px";>
<script>
var xyz = ChangeImage();
document.getElementById("logo").style.backgroundImage = "url('" + xyz + "')";
</script>
</div>
</body>
</html>
Code:
<!DOCTYPE html>
<html lang = "en">
<head>
<script>
function ChangeImage(param)
{
return("[URL unfurl="true"]http://localhost/tlushim/images/greensilver.gif");[/URL]
}
</script>
</head>
<body>
<div id="logo" style = "height:400px; width:400px";>
<?php
echo '<script>',
'var xyz = ChangeImage"('" + 1 + "')";',
'document.getElementById"('" + logo +"')".style.backgroundImage = "url('" + xyz + "')";',
'</script>'
?>
</div>
</body>
</html>
I dont know how to run JS code from PHP.
Could anyone help me with that please?
Thanks