# How to disable a function after clicking on a button ?

**URL:** <https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 20, 2018, 9:29am UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441 "2018-03-20T09:29:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nucky](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nucky](https://forum.wixstudio.com/u/nucky)\
**Post date:** [March 20, 2018, 9:29am UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/1 "2018-03-20T09:29:31Z")

</div>

Hello,

I would like to know how to disable a function in the code after clicking a button, and reactivating it after clicking on another one.

Here is what I’m trying to do :

- I have an infinite loading script on a repeater page, so as the user scrolls down, it will automatically load more items

- I have a ‘go to top’ button and a ‘go to footer’ button

- I want the user to be able to access the footer if he clicks the ‘go to footer’ button, by doing so, it needs to disable the infinite loading script

- The infinite loading function would be enabled again as the users exits the footer

Here is the infinite loading script (triggered everytime the user reaches the line under the repeater)

```javascript
export function line12_viewportEnter(event, $w) {
	
	//shows 'loading more items' text message
	$w('#text73').show();
	
	//automaticly loads more items upon reaching the bottom of the page
	$w("#dynamicDataset").loadMore()
      .then( () => {
      console.log("Done loading more data");
    });
}

```

Thank you !

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [March 20, 2018, 10:09am UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/2 "2018-03-20T10:09:48Z")

</div>

Hi,  
How about creating a boolean global variable and insert it as condition the function that loads more data from the dataset.

```javascript
 let loadMore = true;
 function scrollDown() {
     loadMore = false;
     scrollToFooter(); 
     setTimeout(() => {
         loadMore = true;
     },2000);
 }
 
export function line12_viewportEnter(event, $w) { 
//shows 'loading more items' text message 
    if (loadMore) {
        $w('#text73').show(); //automaticly loads more items upon reaching the bottom of the page 
        $w("#dynamicDataset").loadMore() 
        .then( () => {       
            console.log("Done loading more data"); 
        });
    }
}

```

What do you think ?  
Roi

---

<div class="post-metadata">

**Author:** ![nucky](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nucky](https://forum.wixstudio.com/u/nucky)\
**Post date:** [March 20, 2018, 8:25pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/3 "2018-03-20T20:25:38Z")

</div>

Hi, thanks a lot but it doesn’t work, it shows an error on :

scrollToFooter();

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [March 21, 2018, 8:52am UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/4 "2018-03-21T08:52:16Z")

</div>

Hi,  
I’ve should of write a comment that it’s a scrollToFooter() is a pseudo code.  
You need to use scrollTo method.  
Roi

---

<div class="post-metadata">

**Author:** ![nucky](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nucky](https://forum.wixstudio.com/u/nucky)\
**Post date:** [March 23, 2018, 12:04pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/5 "2018-03-23T12:04:07Z")

</div>

Hi,

I can’t find any ScrollTo function.

Can you please perhaps provide with the bit of code ?

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [March 25, 2018, 7:23am UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/6 "2018-03-25T07:23:50Z")

</div>

Hi,  
[Here](https://www.wix.com/code/reference/wix-window.html#scrollTo) you have scrollTo function with an example.  
Good luck!  
Roi

---

<div class="post-metadata">

**Author:** ![nucky](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nucky](https://forum.wixstudio.com/u/nucky)\
**Post date:** [March 25, 2018, 12:27pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/7 "2018-03-25T12:27:32Z")

</div>

Thanks a lot !

I made some research and tweaked it a little and I managed to achieve what I was trying to.

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [March 25, 2018, 12:29pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/8 "2018-03-25T12:29:03Z")

</div>

Great!

---

<div class="post-metadata">

**Author:** ![nucky](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nucky](https://forum.wixstudio.com/u/nucky)\
**Post date:** [March 25, 2018, 12:31pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/9 "2018-03-25T12:31:06Z")

</div>

Here is the code for those who want :

```javascript
//goes to footer upon clicking the button and disables autolaod
let loadMore = true;
export function button33_click(event, $w) {
     loadMore = false;
     wixWindow.scrollTo(0, 9999);
     setTimeout(() => {
         loadMore = true;
     },2000);
 }

     
export function line12_viewportEnter(event, $w) {
	//automaticly loads more items upon reaching the bottom of the page 
    if (loadMore) {
    //shows loading message and then loads more items
        $w('#text73').show(); 
        $w("#dynamicDataset").loadMore() 
        .then( () => {       
            console.log("Done loading more data"); 
            //hides 'loading more' text message after successful loading
            $w('#text73').hide();
         });
    }
     else {
     	//hides the 'loading more' message if there is no item left to load
         // I couldn't find a way to display a "no more results found message
         //instead
     	 	$w('#text73').hide();
        }
}

```

Just one comment Roi, what is the setTimeOut purpose here ?

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [March 25, 2018, 1:51pm UTC](https://forum.wixstudio.com/t/how-to-disable-a-function-after-clicking-on-a-button/24441/10 "2018-03-25T13:51:18Z")

</div>

It’s a hacky way to reset the loadMore to true so the next time you scroll down it will try to load more.  
Roi
