# TextInput and Number

**URL:** <https://forum.wixstudio.com/t/textinput-and-number/31957>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [June 23, 2020, 1:55pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957 "2020-06-23T13:55:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jga2210](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jga2210](https://forum.wixstudio.com/u/jga2210)\
**Post date:** [June 23, 2020, 1:55pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/1 "2020-06-23T13:55:45Z")

</div>

Please, I need your help.  
I would like to use an “Text Input” ( #input1) to input a number into Collection ( “Tarif” ) but it doesn’t work. The value is null or it’s a string.  
It’s ok when I use a “Text Box” but not with “Text Input”.

export function button1\_click(event) {  
**let** user = wixUsers.currentUser;  
**let** userId = [user.id;](user.id;  
let)  
[**let**](user.id;  
let) inValue = parseFloat($w( ‘#input1’ ).value, 2);  
wixData.query( “Tarif” )  
.eq( “\_id” ,userId)  
.find()  
.then( (results) =\> {  
[//console.log](https://console.log)(results.items[0]);  
**let** toSave = {  
“prix\_mois” : inValue  
};  
[//console.log](https://console.log) (inValue);  
wixData.save( “Tarif” , toSave)  
// [//wixData.update](https://wixData.update)(“Tarif”, toSave);  
});  
}

 ![](https://us1.discourse-cdn.com/wix/original/3X/4/b/4b1db91c25ab16890e6cdb42f875beded1ef866e.png)

Thx for your help !

---

<div class="post-metadata">

**Author:** ![anon72313111](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon72313111](https://forum.wixstudio.com/u/anon72313111)\
**Post date:** [June 23, 2020, 2:08pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/2 "2020-06-23T14:08:51Z")

</div>

Hi,

Try changing the text input type to Number, or just change its value to number, and use [**wixData.update()**](https://www.wix.com/corvid/reference/wix-data.html#update) instead.

Force the value to be a number:

```javascript
let value = Number($w('#input1').value);

if (typeof value === 'number') {
    inValue = value
} else {
    console.warn('The value is not type of number')
}

```

update the fields inside the query:

```javascript
wixData.query("Tarif").eq("_id",userId).find()
    .then(async(results) => {
    if (result.items.length > 0) {
        let item = result.items[0];
        item["prix_mois"] = inValue;
        
        await wixData.update("Tarif", item).then(()=> {
            console.log('The item was saved!')
        }).catch((err) => {
            console.error('The update process failed!')
            console.error(err);
        })
    } else {
        console.warn("Search didn't find any match");
    }
}).catch((err) => {
    console.error('The search process failed!')
    console.error(err);
})

```

Hope that helped~!  
Ahmad

---

<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:** [June 23, 2020, 2:10pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/3 "2020-06-23T14:10:58Z")

</div>

Hello jga2210,

yes it’s a known little problem, also to me.  
But there is a simple way to solve this problem.

Look:  
You have a DATABASE witch is full of data. Every row has another TYPE right?

1. String
2. IMAGE
3. Boolean
4. NUMBER and so on…

Your problem is taht you want compare or set NUMBER with STRING, but a number is not a string! You can count with numbers with strings you can’t.

EXAMPLE: (NUMBER) ----\> 1+2 =3  
EXAMPLE: STRING ---------\> “1”+“2” = ??? ----\> RIGHT —\> “12”

Well, so how to handle it now?  
You can convert NUMBERs into STRINGs, or do it vice versa and convert STRINGs into NUMBERs before handle your futher actions.

Convert STRING to NUMBER:

```javascript
let myNumber = Number("33") ---> 33 (no STRING anymore)

```

Convert NUMBER to STRING:

```javascript
let myString=(33).toString()

```

How to check which type it is?

```javascript
console.log(typeof myString) ---> should be "String"
console.log(typeof myNumber) ----> should be "Number"

```

So, now you should know everything useful, to solve your problem.😁

---

<div class="post-metadata">

**Author:** ![jga2210](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jga2210](https://forum.wixstudio.com/u/jga2210)\
**Post date:** [June 23, 2020, 10:00pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/4 "2020-06-23T22:00:30Z")

</div>

Yes I’ve the same conclusion 🙂  
But I don’t understand.  
Inputbox is type NUMBER  
Cell in database is type NUMBER  
typeof is NUMBER  
but finally the value was inserted = 0

---

<div class="post-metadata">

**Author:** ![jga2210](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jga2210](https://forum.wixstudio.com/u/jga2210)\
**Post date:** [June 24, 2020, 7:58am UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/5 "2020-06-24T07:58:39Z")

</div>

Thanks You Ahmad,  
It’s better but not yet good ☹

Console.Log → ( ‘The item was saved!’)  
but the value has been inserted is 0.  
I think I’ve a problem with let inValue and let value ?

export function button1\_click(event) {  
**let** user = wixUsers.currentUser;  
**let** userId = user.id;  
**let** inValue;  
**let** value = Number($w( ‘#input1’ ).value);  
**if** ( **typeof** value === ‘number’ ) {  
inValue = value  
//value is a number but = 0  
} **else** {  
console.warn( ‘The value is not type of number’ )  
}  
wixData.query( “Tarif\_abo” ).eq( “userId” ,userId).find()  
.then( **async** (results) =\> {  
**if** (results.items.length \> 0 ) {  
**let** item = results.items[0];  
item[“prix\_mois”] = inValue;  
**await** wixData.update( “Tarif\_abo” , item).then(()=\> {  
console.log(‘The item was saved!’)  
}). **catch** ((err) =\> {  
console.error( ‘The update process failed!’ )  
console.error(err);  
})  
} **else** {  
console.warn( “Search didn’t find any match” );  
}  
}). **catch** ((err) =\> {  
console.error( ‘The search process failed!’ )  
console.error(err);  
})  
}

 ![](https://us1.discourse-cdn.com/wix/original/3X/6/2/62f484c68da96dcc9d2f189691cf61a75ea1b89e.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:** [June 24, 2020, 9:34pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/6 "2020-06-24T21:34:48Z")

</div>

Hello jga2210,

could you solve your problem here?

---

<div class="post-metadata">

**Author:** ![jga2210](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jga2210](https://forum.wixstudio.com/u/jga2210)\
**Post date:** [June 24, 2020, 9:57pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/7 "2020-06-24T21:57:37Z")

</div>

No ☹  
I don’t understand where is the problem

---

<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:** [June 24, 2020, 10:16pm UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/8 "2020-06-24T22:16:56Z")

</div>

Ok, i will check tomorrow.

---

<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:** [June 25, 2020, 11:18am UTC](https://forum.wixstudio.com/t/textinput-and-number/31957/9 "2020-06-25T11:18:20Z")

</div>

Ok, you had an issue with the correct input of NUMBERS into database, right?  
I just tried to make an example, it’s finaly not completed, but should you demonstrate that it works, take a look here…  
[https://russian-dima.wixsite.com/meinewebsite/blank](https://russian-dima.wixsite.com/meinewebsite/blank)

```javascript
function myFunktion (parameter) {
    var inValue
    let user = wixUsers.currentUser;
    console.log(user)
    let userId = user.id;
    console.log(userId)
    inValue = Number(parseFloat($w('#input2').value, 2));
    console.log(inValue)
​
    let toSave = {"prix_mois": inValue};
 
    wixData.save("Tarif", toSave)
    .then( (results) => {
        let item = results; //see item below
    } )
}

```

Your reference-column has to be set to NUMBER.  
I used a STRING-input-field. (In this example INPUT-2).
