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.”;
});
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
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.
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;
});
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
});
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