Hi,
Like I have a entry and exit radio buttons, how to show the time of entry and exit in database connected to it and find the total time duration of being active.
You can do it with a query of a triggere-event of a button.
When button clicked, save the time into my database.
This example could help you understanding it a little bit better…
https://russian-dima.wixsite.com/meinewebsite/date-time-onclick
- First creating a query for a button-click-event.
Something like—>“onClick.myButton” ----> start my function
$w.onReady(function() {
$w("#myButtonIDhere").onClick(()=>{
// ....here your code ....
})
})
Now the question, what should now happen, after clicking on the button?
Yes you want to save it into your database right? Then you will need a code-snipet which will do this action… like …
- example…
import wixData from 'wix-data';
let toInsert = {
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
wixData.insert("myCollection", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
- Of course you will have to put this two parts together and modify the code…
import wixData from 'wix-data';
$w.onReady(function() {
$w("#myButtonIDhere").onClick(()=>{ // ---> or onChange if using Radio-Buttons
// ....here your code ....
let newTime = //put in here what you have learned in the given example.
let toInsert = {"exitTime": newTime};
wixData.insert("HereNameOfYourCollection", toInsert)
.then( (results) => {
let item = results;
console.log(results)
} )
.catch( (err) => {
let errorMsg = err;
} );
})
})
Thanks,
but how to choose the different radio button values like when I will work on the code, how to choose that at this time entry and exit are marked, I mean how to pass the parameters to onClick() function.
Like When I click on entry the value time should be in entry column and same for the exit column. But now when I am clicking on any button the time get stored to entry column.
what for that?
Here a step further… something like this one…
import wixData from 'wix-data';
$w.onReady(async function() {
$w("#RBG1").onChange(()=>{ //<------RBG1 = RadioButtonGroup1
let newTime = await xyz()
console.log(currentTime) // <---currentTime-value
let toInsert = {"exitTime": newTime};
wixData.insert("HereNameOfYourCollection", toInsert)
.then( (results) => {
let item = results;
console.log(results)
} )
.catch( (err) => {
let errorMsg = err;
} );
})
})
function xyz() {
const today = new Date();
let currentTime = today.toLocaleTimeString()
console.log(currentTime)
return (currentTime)
}
@russian-dima Really like what you are doing on this forum. You must be in a different time-zone, because you beat me to it on almost every answer. “Meinewebsite”? German?
@giri-zano
Hey Giri , you are right, i am
GER.
Yes see you here very often ^^.
Also read your threads ^^
Yes—> Meinewebsite—> my small one.
The big one is growing ^^
@giri-zano
P.S. You were one of the guys, who made me CORVID atractive including Yisrael and J.D. (and some other like G.O.S and few other). Now here i am after 7-8-month intensiv studying JS and CORVID ^^.
@russian-dima Yes, we all got bumped up to Masters. Have you applied yet?
@giri-zano
Applied to become a corvid-master?
Oh no, i have still to grow, to get this badge
I still can’t answer all questions (but i hope soon).
I am intensively working on it.