Function doesn't return value on hover

I’m trying to save a different value depending on if a user clicks a Yes or No button. Unfortunately, my function won’t return a value on hover, so I can’t save which button the user clicked. What am I missing here? I just have 2 buttons: yes and no.

let ID = $w(“#button30”).onMouseIn( (event, $w) => {
//Add your code for this event here:
$w(“#text89”).text=“no”;
return “no.”;
});

$w(“#input10”).value = ID;

Thanks!

When I store input10 in the database, nothing is stored. It’s a null value.

Hello,

Try following the code below and let me know if it solves the problem. What I think is happening is that it is submitting before the onmousein event happens.

let ID;
 $w("#button30").onMouseIn( (event, $w) => {
 //Add your code for this event here: 
    $w("#text89").text="no";
    ID =  $w("#text89").text;
});

$w("#input10").value = ID;
//insert into database normally

Let me know if this helps,
Majd

No, that doesn’t work.

Right now I have input10 show as a value, so it still doesn’t work. And, the database is still null. Any other ideas?

Also, why would the onmousein event happen after submission? You need to move your mouse over a button before you can click on it. And, I can see the onmousein event get triggered because I’m displaying the copy #text89 for debugging.

Hello,

Can you post your full page code? Are you using wixData.insert() correctly to insert into a database? Look here for more info on inserting to a database.

This is my entire page of javascript. I’m using the editor’s GUI to connect the submit button to the page. I’m not using the insert() function. Do I need to do that in order for this to work? If so, why? Thanks!

import wixLocation from ‘wix-location’;

$w.onReady( function () {
//TODO: write your page related code here…

let url = wixLocation.url;

$w(“#input5”).value= url;

let ID;
$w(“#button30”).onMouseIn( (event, $w) => {
//Add your code for this event here:
$w(“#text89”).text=“no”;
ID = $w(“#text89”).text;
});

$w(“#input10”).value = ID;

});

Ok. I looked up the documentation. Now I’m trying to use, wixData.insert(), but it still doesn’t seem to work. Any thoughts?

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;

let url = wixLocation.url;

$w.onReady( function () {
//TODO: write your page related code here…

let ID = $w(“#button30”).onMouseIn( (event, $w) => {
//Add your code for this event here:
$w(“#text89”).text=“no”;
ID = $w(“#text89”).text;
return ID
});

$w("#input10").value = ID; 
$w("#input5").value = url; 

let toInsert = {
“Vote”: ID,
“Source”: url,
};

wixData.insert("Signups", toInsert) 
    .then( (item) => { 
        $w("#input10").value = item.Vote; 
        $w("#input5").value = item.Source; 
    } ) 
    . **catch** ( (err) => { 

let errorMsg = err;
} );

});

Hey Tali,

There are a few flaws in your code.
If you want to save some info when a user clicks a button, you should use the onClick method instead of onMouseIn.
The code saving the item (or doing any action triggered by the click) must be inside the onClick handler.

Here is a snipped you could use:

import wixLocation from ‘wix-location’
import wixData from ‘wix-data’

let url = wixLocation.url

$w.onReady(function() {
$w(‘#button30’).onClick((event, $w) => {
const ID = $w(‘#text89’).text

let toInsert = { 
  Vote: ID, 
  Source: url 
} 

wixData.insert('Signups', toInsert).catch(err => console.log(err)) 

})
})