Save a number to a database depending on which tag or checkbox group is selected when you click a button

So I need to assign point values depending on the results of winning a competition. Points are cumulative, and need to eventually be added to a final score.

[addpoints] number field
[award] tag field

In the form a person would [award] the placement of the winner (first, second, third) and depending on which award is chosen the winner gets 3, 2, 1, or 0 points in [addpoints]. 3 points for first place, 2 for second, 1 for third, 0 for no award earned.

I know using a dropdown selector for assigning the award would be easier. However, this is a tiered. So a winner would go on to a winners circle, and judged again, and earn different awards like “Best in Show”, which will also get added to the [award] field using a different form.

For the life of me, I cannot figure out why this doesn’t actually work. What am i missing?

import wixData from 'wix-data';
export function button1_click(event) {
let award = $w("#award").options;
if (!award === "First") {
let place = 3;
$w('#dataset1').setFieldValue('addpoints', place);
}

else if (!award === "Second") {
let place = 2;
$w('#dataset1').setFieldValue('addpoints', place);
}

else if (!award === "Third") {
let place = 1;
$w('#dataset1').setFieldValue('addpoints', place);
}

else {
let place=0;
$w('#dataset1').setFieldValue('addpoints', place)}

}
}

Note that when you use setFieldValue you need to then save those again back to your dataset as shown in the Wix API Reference.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue

setFieldValue( )
Updates the value of a field in the current item.

Description
The setFieldValue function sets the value of a field in the current item. Setting a field value fires an onItemValuesChanged event when the page elements connected to the field have been updated with the new value.

Setting the value of a field in a dataset item does not immediately set that value in the collection that the dataset is connected to. You still need to call the dataset save() function or any other function that performs a save to have the new value reflecting in the collection.

Calling setFieldValue() on a read-only dataset causes an error.

Examples

Set a field’s value

$w("#myDataset").setFieldValue("title", "New Title");

Set a field’s value and save the item to the connected collection

$w("#myDataset").setFieldValue("title", "New Title");
$w("#myDataset").save();

Set a field’s value when the page loads

$w.onReady( () => {
  $w("#myDataset").onReady( () => {
    $w("#myDataset").setFieldValue("title", "New Title");

  } );
  
} );

right, so that isn’t very helpful.

the issue is that this is a on click event. and one a Submit button, which will actually perform the save dataset function. adding a save to the event causes an error by duplicating the save.

I’ve determined that !award is wrong, and that award !== “First” isn’t actually checking to see if the option was selected, just proving that “first” was an option.

so if you got some insight on how to correct the code, that might be helpful

Used Code

import wixData from 'wix-data';

let first = 3;
let second = 2;
let third = 1;
let fourth = 0;

export function button1_click(event) {
let award = $w("#award").value;
if (award === "first") {
$w('#myDataset').setFieldValue('addPoints', first);
$w("#myDataset").save();

} else if (award === "second") {
$w('#myDataset').setFieldValue('addPoints', second);
$w("#myDataset").save();

} else if (award === "third") {
$w('#myDataset').setFieldValue('addPoints', third);
$w("#myDataset").save();

} else {
$w('#myDataset').setFieldValue('addPoints', fourth);
$w("#myDataset").save();
}
}

So, still not very helpful?

Forum Guidelines, then please take note of this one.

No Freebies.
Don’t expect anyone to provide code snippets or full solutions; the community is here to help you learn how to solve problems.