Separating input values into rows in the dataset

Is there a way to submit data into a collection which creates multiple rows for each input selection?

Each row would have the same fullName and emailAddress values, but varying values for the sessionName.

I’ve attached a screenshot of the result I’d want. Thank you!

This is what I’m using so far, and I figured I can just duplicate the “toInsert” function but I can’t :frowning:

export function button1_click ( event ) {

let toInsert = {
“fullName” : $w ( ‘#input1’ ). value ,
“emailAddress” : $w ( ‘#input2’ ). value ,
“sessionName” : $w ( ‘#input3’ ). value ,
“sessionName” : $w ( ‘#input4’ ). value ,
“sessionName” : $w ( ‘#input5’ ). value ,
};

wixData . insert ( “CVENTRegistration” , toInsert )
. then ( ( results ) => {
let item = results ; //see item below
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );

}

$w.onReady(function() {
    $w('#button1').onClick(()=>{xxx();});
});


function xxx(){
    let toInsert = [
        {"fullName":$w('#input1').value, "emailAddress":$w('#input2').value, "sessionName":$w('#input3').value},
        {"fullName":$w('#input1').value, "emailAddress":$w('#input2').value, "sessionName":$w('#input4').value},
        {"fullName":$w('#input1').value, "emailAddress":$w('#input2').value, "sessionName":$w('#input5').value},
    ];

    wixData.bulkInsert("CVENTRegistration", toInsert)
    .then((results)=> {let item = res; console.log(res);})
    .catch((err)=>{let errorMsg = err;});    
}

Another example of how to generate an → “bulkInsert” you will find here…

Thank you so much! This works. Is there a way to not insert into dataset if a value is null? For example if nothing was entered in #input5

Anyway to merge something like…

if ( $w ( ‘#dropdown4’ ) !== null )

{ “fullName” : $w ( ‘#input1’ ). value , “emailAddress” : $w ( ‘#input2’ ). value , “sessionName” : $w ( ‘#dropdown4’ ). value },

@motiontc
You can use an alternative coding-way to code it…

import wixData from 'wix-data';

$w.onReady(function() {$w('#button1').onClick(()=>{xxx();});});

function xxx(){
    let toInsert = [], data = {};
    let inputAmount = 5;        
        for (let index = 1; index < inputAmount-2; index++) {           
            data.fullName = $w('#input1').value; 
            data.emailAddress = $w('#input2').value 
            //--------------------------------------
            data.sessionName = $w('#input'+(index+2)).value
            toInsert.push(data);
        }
        
        if ($w('#dropdown4').value) {
            data.fullName = $w('#input1').value;  
            data.emailAddress = $w('#input2').value 
            data.sessionName = $w('#dropdown4').value
        }
    wixData.bulkInsert("CVENTRegistration", toInsert)
    .then((res)=> {let item = res; console.log(res);})
    .catch((err)=>{let errorMsg = err;});    
}

This is just an quick generated example, which might not work correctly, but it should show you how to generate your wished functionality.