How to get input from textbox

This is my code in Update button.

I need to use input from textbox ID to search update location and textbox Value to increased value in DB.

export function button1_click(event) {
// …
let toInsert = {
“ID”: “C003”, //how to get input from textbox.
“value”: 10 //how to increased value in DB such as DB has value 15 then i add 10
//DB must increased value to 25.
};

wixData.insert(“ChamokInventory”, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );

}

Hi Shiro,

Let’s say the ID of the text component is ‘#text1’.
You can get the info inside it that way:

const textIntextBox = $w('#text1').text;

Two steps for updating a data base record:

  1. Read the existing record - using wixData.query()
  2. Write the updated one - using wixData.update()

Liran.

thank you for help, but i have some problem in editor my code is fine. but in preview system say
Error: Can’t use $w for selection components before the page is ready.


this is my code.

import wixData from ‘wix-data’;
const inID= $w(‘#inputID’).id;

export function button1_click(event) {
let toInsert = {

“code”: inID,
“title”: “box.”,
“type”: “tool”,
“value”: 10
};

wixData.insert(“ChamokInventory”, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );

}

Hi,

Just move the following line:

const inID= $w('#inputID').id;

To be inside of your ‘onClick’ function.

Liran.

I did it!! Super thanks bro.

I have a last question.
My textbox input is number type, but when insert to DB it change to string.
How to fix it.
My code.
const inID = $w(‘#idSe’).value;
const inValue = $w(‘#input1’).value; // this is textbox input value number.

let toInsert = { 

	"code": inID, 
	"value": inValue 
}; 

const inValue = $w(‘#input1’).value;

Did you solve this issue?