# Repurposed code for different button not working 

**URL:** <https://forum.wixstudio.com/t/repurposed-code-for-different-button-not-working/34763>\
**Category:** Ask the community\
**Tags:** wix-bookings, question, code\
**Created:** [September 30, 2022, 12:59pm UTC](https://forum.wixstudio.com/t/repurposed-code-for-different-button-not-working/34763 "2022-09-30T12:59:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![founder53806](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/founder53806/32/25911_2.png) [@founder53806](https://forum.wixstudio.com/u/founder53806)\
**Post date:** [September 30, 2022, 12:59pm UTC](https://forum.wixstudio.com/t/repurposed-code-for-different-button-not-working/34763/1 "2022-09-30T12:59:46Z")

</div>

Can someone tell me why, when I copy and paste this code in line, and change the button it’s referencing (changed button4 to button41 in all 3 places its referenced), why when clicking button41, the same thing isn’t executed???

This is the only reference to button4 in the page code.

Could it be something in some other code somewhere?? What can I be missing?  
All I want to do is duplicate the functionality

export function button4\_click ( event ) {  
$w ( ‘#button4’ ). disable ()  
**let** toInsert = {  
propAvailabilityDate : data . \_id ,  
member : wixUsers . currentUser . id ,  
availabilityDate : data . weekAvailable ,  
property : data . property . \_id  
}  
wixData . insert ( “BookingemailClicks” , toInsert ). then (() =\> {  
**let** date = sortDate ( data . weekAvailable )  
// console.log(“mailto:” + data.property.bookingsEmail + "?subject=Booking " + data.property.title + " from " + date )  
wixLocation . to ( “mailto:” + data . property . bookingsEmail + "?subject=Booking " + data . property . title + " from " + date )  
$w ( ‘#button4’ ). enable ()  
//$w(‘#bookedStrip’).expand()  
})  
}

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 2, 2022, 9:12pm UTC](https://forum.wixstudio.com/t/repurposed-code-for-different-button-not-working/34763/2 "2022-10-02T21:12:38Z")

</div>

Try this one instead…

```javascript
$w.onReady(()=>{
    $w('#button4').onClick((event)=>{
      console.log(event.target.id);
	  $w('#button4').disable();
       let toInsert = {
          propAvailabilityDate: data._id,
          member: wixUsers.currentUser.id,
          availabilityDate: data.weekAvailable,
          property: data.property._id
      }

  wixData.insert("BookingemailClicks", toInsert).then(()=> {
      let date = sortDate(data.weekAvailable);
      wixLocation.to("mailto:" + data.property.bookingsEmail + "?subject=Booking " + data.property.title + " from " + date);
      $w('#button4').enable()
    });  
});

```

Normaly the button should work. Take a look into the CONSOLE.

Don’t use EXPORT-FUNCTIONS, they are tricky.  
Instead use the shown CODE-STRUCTURE, this type of coding is more save & realible.

---

<div class="post-metadata">

**Author:** ![founder53806](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/founder53806/32/25911_2.png) [@founder53806](https://forum.wixstudio.com/u/founder53806)\
**Post date:** [October 6, 2022, 1:32pm UTC](https://forum.wixstudio.com/t/repurposed-code-for-different-button-not-working/34763/3 "2022-10-06T13:32:08Z")

</div>

thanks will look into it
