Insert particular field of new collection from other collection

I want to make a form consist of:

  1. event (#Input4 - taking from other collection (“EventList” w/ 4 fields in it))
  2. fullname (user Input)
  3. email (user Input)
  4. phone (user Input)

I’m able to insert event (#Input4) from collection using code below, however when I click submit, only the user input is saved in database (“RegistrationData”). The #Input4 that I can see from the form is not save to database.

import wixData from ‘wix-data’ ;
$w . onReady ( function () {
wixData . query ( “EventList” )
. limit ( 1 )
. find ()
. then (( result ) => {
let items = result . items
let item = items [ 0 ]
let dodol = item . event
$w ( ‘#input4’ ). value = dodol
})
})

Anyone can help ?

Thanks.

No one can help? Please?

Congrats. You were the 10.000-th user who asked this question. Look at setFieldValue(). And next time, please search first or have a look at the right “Similar posts” pane.

Sorry I don’t understand. setFieldValue() in the example is based on specific value. It’s not based on the result of the query. I want to insert value to collection based on query that already displayed in the page (part of the form). As I said in the description above, the other 3 fields is based on user input, while 1 field is based on query.

OK, so I guess it’s not connected to a dataset then. What you should do is get the .value (s) from the form elements (or .src for an image or .checked for checkboxes), prepare an object and insert it into the db using https://www.wix.com/velo/reference/wix-data/insert

Thanks for the reply. Let me change my question for different purpose but same idea. How to assign the query result to a Global variable? so I can use the variable for other function.
Here is my query code:

import wixData from ‘wix-data’ ;

$w . onReady ( function () {

wixData . query ( “EventList” )
. limit ( 1 )
. find ()
. then (( result ) => {
let items = result . items
let item = items [ 0 ]
let dodol = item . event
$w ( ‘#eventNameButton’ ). value = dodol
})
})

Currently, I assign variable ‘dodol’ to #eventNameButton (I have no issue to display the result in the textbox ).

I’m going to use the variable ‘dodol’ ( “#eventNameButton” ) to filter my dropdown list. This is where I got stuck. When I preview, the dropdown list works as intended (the filter is working properly) . But when I publish it, the filter doesn’t work. All items are show up in the dropdown list (filter doesn’t work).

This is my dropdown code:

function uniqueDropDown1 (){

wixData . query ( “GameRegistration” )
. contains ( “eventName” , $w ( “#eventNameButton” ). value )
. ascending ( “playerName” )
. limit ( 100 )
. find ()
. then ( results => {
const uniqueTitles = getUniqueTitles ( results . items );
$w ( “#playerNameButton” ). options = buildOptions ( uniqueTitles );
});

function getUniqueTitles ( items ) {
const titlesOnly = items . map ( item => item . playerName );
return [… new Set ( titlesOnly )];
}
function buildOptions ( uniqueList ) {
return uniqueList . map ( curr => {
return { label : curr , value : curr };
});

}
}

Appreciate your help!

Never mind… after tried multiple attempts, I got solution for my need!