# Why does my page reload after calling a function?

**URL:** <https://forum.kirupa.com/t/why-does-my-page-reload-after-calling-a-function/326389>\
**Category:** Uncategorized\
**Created:** [December 11, 2011, 5:23am UTC](https://forum.kirupa.com/t/why-does-my-page-reload-after-calling-a-function/326389 "2011-12-11T05:23:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wes\_design](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wes\_design](https://forum.kirupa.com/u/wes_design)\
**Post date:** [December 11, 2011, 5:23am UTC](https://forum.kirupa.com/t/why-does-my-page-reload-after-calling-a-function/326389/1 "2011-12-11T05:23:36Z")

</div>

```auto
 function changeBGimage(){
    var imgSrc = new Array();
    imgSrc[0]="url('images/cons_1.png')";
    imgSrc[1]="url('images/cons_2.png')";
    imgSrc[2]="url('images/cons_1.png')";
    var no = Math.floor(Math.random()*2);
    var bg = document.getElementById("background");
    bg.bgColor="#ffccaa";
    //alert(bg.style.backgroundImage);
    bg.style.background=imgSrc[no];
   
    bg.style.backgroundRepeat="no-repeat";
    bg.style.backgroundPosition="0 0";
    bg.style.border="solid 1px"//bg.style.backgroundColor="#ffccaa";
    //alert(bg.style.backgroundImage);
    var i = 1;
    alert(i++);
    //new Date();
    
    
    

}

```

^I have the following function that I call onCLick, and after the function is called the page automatically reloads itself and makes the effect in null, is there something I a missing that causes this unnecessary re-loading of the page?
