I have looking other post for this problem (because there are, of course). But I even didn't succeed with the answer of these other post.
Then, my issue :
I have the following script to open an image randomly
<script> function banner()
{var img = new Array();
img[0]='images/hochbau1.jpg';
img[1]='images/hochbau2.jpg';
img[2]='images/hochbau3.jpg';
img[3]='images/hochbau4.jpg';
img[4]='images/hochbau5.jpg';
img[5]='images/hochbau6.jpg';
img[6]='images/hochbau7.jpg';
img[7]='images/hochbau8.jpg';
img[8]='images/hochbau9.jpg';
img[9]='images/hochbau10.jpg';
var n=Math.round((Math.random()*9));
document.write(img[n]);
} </script>
Then, I would like to have this images in this (instead of images/hochbau.jpg) :
<div class="section22" style="background-image:url(images/hochbau.jpg); "> </div>
Then, I tried this:
<div class="section22" style="background-image:url(<script> banner(); </script>);"> </div>
or this
<div class="section22" style="background-image:url(
<script type="text/javascript" language="javascript">
document.write('images/hochbau'+ Math.round((Math.random()*9)+1)+ '.jpg');
</script>
); "> </div>
Then, I changed the script as :
<script> function banner()
{var img = new Array();
img[0]='images/hochbau1.jpg';
img[1]='images/hochbau2.jpg';
img[2]='images/hochbau3.jpg';
img[3]='images/hochbau4.jpg';
img[4]='images/hochbau5.jpg';
img[5]='images/hochbau6.jpg';
img[6]='images/hochbau7.jpg';
img[7]='images/hochbau8.jpg';
img[8]='images/hochbau9.jpg';
img[9]='images/hochbau10.jpg';
var n=Math.round((Math.random()*9));
document.getElementById('myPElement').style.backgroundImage = 'url(img[n])';
} </script>
with the following
<div class="section22" id="myPElement">
But nothing is working..... maybe I am closed to the solution but I am stuck...
if you have some observation, please tell me ! many thanks for your help

document.getElementById('myPElement').style.backgroundImage = 'url(' +img[n]+')';