# How do I connect an onClick event to a database?

**URL:** <https://forum.wixstudio.com/t/how-do-i-connect-an-onclick-event-to-a-database/7775>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 1, 2021, 8:39pm UTC](https://forum.wixstudio.com/t/how-do-i-connect-an-onclick-event-to-a-database/7775 "2021-01-01T20:39:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trewisesr](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/trewisesr/32/25826_2.png) [@trewisesr](https://forum.wixstudio.com/u/trewisesr)\
**Post date:** [January 1, 2021, 8:39pm UTC](https://forum.wixstudio.com/t/how-do-i-connect-an-onclick-event-to-a-database/7775/1 "2021-01-01T20:39:51Z")

</div>

I am designing a simple Boolean input into a database. I created a box, added the onClick event, created a database, created the field in the database to run the test, and verified that all the applicable item had the correct name. I used the following code to make the Boolean field “true”:

$w ( ‘#dataset1’ ). setFieldValue ( “test1” , **true** );

After running the code, I got the error message: DatasetError: There is no current item

What is the problem?

 ![](https://us1.discourse-cdn.com/wix/original/3X/1/8/18507edf09a83bc1e23581b9cf454a343fcb1ba0.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/5/7/5766b4125a86af9f45df4d11db158887b1171a42.png)

---

<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:** [January 1, 2021, 9:13pm UTC](https://forum.wixstudio.com/t/how-do-i-connect-an-onclick-event-to-a-database/7775/2 "2021-01-01T21:13:33Z")

</div>

Long ago there was a thread, very similar to your problem…  
[https://www.wix.com/corvid/forum/community-discussion/keep-switch-on-until-switched-back-by-member/p-1/dl-5ef0a5425de91a0017455aed-5ef079bbf0d26200170de110-1?commentId=5ef079bbf0d26200170de110&origin=notification&postId=5ef01016e0dae4004ab6c2e1&replyId=5ef0a5425de91a0017455aed](https://www.wix.com/corvid/forum/community-discussion/keep-switch-on-until-switched-back-by-member/p-1/dl-5ef0a5425de91a0017455aed-5ef079bbf0d26200170de110-1?commentId=5ef079bbf0d26200170de110&origin=notification&postId=5ef01016e0dae4004ab6c2e1&replyId=5ef0a5425de91a0017455aed)

But i would recommend you another solution, by using the “save”-API-function for example…

```javascript
import wixData from 'wix-data';

let toSave = {"test1":	true};

wixData.save("contactForm", toSave)
	.then( (results) => {
		let items = results.items; 
		console.log(items)
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );

```

The adventage of this solution is, that you do not need any datasets

You could perhaps also use “insert”-API-function…

> **[insert - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/wix-data/insert)**
>
> Adds an item to a collection. The insert() function returns a Promise that resolves to the inserted item after it has been added to the specified collection. ...

Or the “update”-API-function…

> **[update - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/wix-data/update)**
>
> Updates an item in a collection. The update() function returns a Promise that resolves to the updated item from the specified collection. The Promise is ...
