# Database field update onClick

**URL:** <https://forum.wixstudio.com/t/database-field-update-onclick/31001>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [October 18, 2020, 5:56pm UTC](https://forum.wixstudio.com/t/database-field-update-onclick/31001 "2020-10-18T17:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juozmant](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/juozmant/32/82997_2.png) [@juozmant](https://forum.wixstudio.com/u/juozmant)\
**Post date:** [October 18, 2020, 5:56pm UTC](https://forum.wixstudio.com/t/database-field-update-onclick/31001/1 "2020-10-18T17:56:03Z")

</div>

Hi,

Im trying to get index number from repeater, convert it into text, and update certain text field in database after click. I think somewhere around but at the same time not there. Can someone help me? Neither loading if working or data insert.

```javascript
$w.onReady(() => {
$w('#repeaterIndex').onItemReady(($item, data, index) => {
        $item('#updateRankButton').onClick(() => {

 
$w('#updateRankButton').hide
$w('#loadingGifLeaderbords').show

let currentIndex = $w('#dataset4').getCurrentItemIndex();
console.log(currentIndex);
let rankUpdate = Number(index+1).currentIndex();
console.log(rankUpdate)

$w("#dataset4").setFieldValue("rank", rankUpdate );
console.log()
$w('#updateRankButton').show
$w('#loadingGifLeaderbords').hide
})
})
})

```

Thank you!  
@Ahmad  
@J. D.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [October 18, 2020, 6:07pm UTC](https://forum.wixstudio.com/t/database-field-update-onclick/31001/2 "2020-10-18T18:07:05Z")

</div>

There’re a few mistakes in your code.

1. It should be .show **()** , .hide **()** with parenthesis.

2. This part is wrong: Number ( index + 1 ) since index + 1 is already a number.

3. And what is . currentIndex (); ? I’m not sure what you’re trying to do in this line.

4. And this console . log () is empty.

---

<div class="post-metadata">

**Author:** ![juozmant](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/juozmant/32/82997_2.png) [@juozmant](https://forum.wixstudio.com/u/juozmant)\
**Post date:** [October 18, 2020, 6:23pm UTC](https://forum.wixstudio.com/t/database-field-update-onclick/31001/3 "2020-10-18T18:23:10Z")

</div>

Thank for quick response @jonatandor35

With this code its now working, but data is inserted only for first item in collection, but now for the iteam which is in repeater. Where is problem?

```javascript
$w.onReady(() => {
$w('#repeaterIndex').onItemReady(($item, data, index) => {
        $item('#updateRankButton').onClick(() => {

 
$w('#updateRankButton').hide();
$w('#loadingGifLeaderbords').show();

let currentIndex = $w('#dataset4').getCurrentItemIndex();
console.log(currentIndex);
let rankUpdate = index + 1
console.log(rankUpdate)

$w("#dataset4").setFieldValue("rank", rankUpdate );
$w('#updateRankButton').show();
$w('#loadingGifLeaderbords').hide();
$w('#dataset4').save();
})
})
})

```
