How to zip this to get it more compact ?

How can I compress this code even further?

$w('#DD1').onChange((event)=>local.setItem(refFields[0], $w('#DD1').value), MEMrefs[0]=$w('#DD1').value, SEARCH_ENGINE()})
$w('#DD2').onChange((event)=>local.setItem(refFields[1], $w('#DD2').value), MEMrefs[1]=$w('#DD2').value, SEARCH_ENGINE()})
$w('#DD3').onChange((event)=>local.setItem(refFields[2], $w('#DD3').value), MEMrefs[2]=$w('#DD3').value, SEARCH_ENGINE()})
$w('#DD4').onChange((event)=>local.setItem(refFields[3], $w('#DD4').value), MEMrefs[3]=$w('#DD4').value, SEARCH_ENGINE()})
$w('#DD5').onChange((event)=>local.setItem(refFields[4], $w('#DD5').value), MEMrefs[4]=$w('#DD5').value, SEARCH_ENGINE()})

for(let i=0; i<=5;i++){
$w(“#DD”+i+1).onChange((event)=>local.setItem(refFields[i], $w(“#DD”+i+1).value), MEMrefs[i]=$w(“#DD”+i+1).value, SEARCH_ENGINE()})

}

Have fun

Hello Felix, nice to see you again here.
But i have a bad message for you. I already tested such version and i tested your code and it dis not work for me. The same result as i already have had experienced before.

Did you test ist?
Does the code in this structure work for you?

for(let i=0; i<=5;i++){
    $w("#DD"+i+1).onChange((event)=>{   })
}

Hi Dimitri , try to explain that this code is supposed to do , it will be easier for reply :slight_smile:
Regards

Let us take just this example here…

for(let i=0; i<=5;i++){
    $w("#DD"+i+1).onChange((event)=>{ console.log("#DD"+i+1) })
}

Yes, like you i had the same idea (the same code) to controll all my DropDowns with just 3-lines of code (with a for loop).
But this seems not to work like this.

5-DropDowns have to be controlled and i do not want this one…

$w("#DD1").onChange((event)=>{ console.log("#DD1")})
$w("#DD2").onChange((event)=>{ console.log("#DD2")})
$w("#DD3").onChange((event)=>{ console.log("#DD3")})
$w("#DD4").onChange((event)=>{ console.log("#DD4")})
$w("#DD5").onChange((event)=>{ console.log("#DD5")})

I want it, like in your attempt in a loop or a similar solution, where it works.

Ok, nevermind Felix it’s ok.

I will do it within a function, which will be called by every of the dropdowns.
This works for me, too. Like this one…

$w("#DD1").onChange((event)=>{ function X() )
$w("#DD2").onChange((event)=>{ function X() )
$w("#DD3").onChange((event)=>{ function X() )
$w("#DD4").onChange((event)=>{ function X() )
$w("#DD5").onChange((event)=>{ function X() )

//This is also good, but this is not realy a compress-solution 😁
$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{function X())

//And while a was writing this post, i had an idea, like this one....
$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{console.log(event.target.id), MEMrefs[0] = $w(event.target.id).value, SEARCH_ENGINE()})

// or even....
$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{console.log(event.target.id), MEMrefs[0] = $w(event.target.id).value, SEARCH_ENGINE(event)})

//YES, this is the right way. This could be the key to my solution.

//---> here i can get the number of ---> MEMrefs[0] 
//event.target.id = DD1 / DD2 / DD3 ...and so on

//cutting the number of DropDown of the result ---> DD[3]

// I hope you understand, what i mean. 

This is already the solution…

$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{ }

—> EVENT is the key.

Nevertheless many thanks
You got me thinking. :grin:

Some extra-info…
With this code-snipet i have my compress-function and also know, which of the DropDowns was changed/clicked or pressed, or whatever…

$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{
    let selectedDD = event.target.id[event.target.id.length - 1];
    console.log(selectedDD)
}

And with this you can work, and do what ever you want (related to my first given example-code)

$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{
  let selectedDD = event.target.id[event.target.id.length - 1];
  console.log(selectedDD)
  let selectedID = event.target.id
  console.log(selectedID)
  local.setItem(refFields[selectedDD], $w(selectedID).value)
  MEMrefs[selectedDD]=$w(selectedID).value 
   SEARCH_ENGINE()
})

Not tested, but this should work. As you can see, a very flexible one…:wink:

And it’s me one more time…
As assumed, it did work for me. This is what i was searching for…

$w('#DD1,#DD2,#DD3,#DD4,#DD5').onChange((event)=>{
        console.log(event.target.id)
 let selectedDD = Number(event.target.id[event.target.id.length - 1])
        console.log(selectedDD)
 
        MEMrefs[selectedDD-1] = $w('#'+event.target.id).value
        console.log("MEMref" + selectedDD + " = " + MEMrefs[selectedDD-1])
        SEARCH_ENGINE()
    })

If you are interessted, here you will find soon this code-snipet in ACTION :wink:

https://www.media-junkie.com/pflegeservice

All related to this post here…