Changing the text of a textbox with a button

Hello all!

I have read many posts and the API references but I still have the same problem…
I try to change the text of a textbox when the user clicks a button.

I’m not sure where the problem is, is it because I have to call he function somewhere?

Here is my code:

export function button1_click(event, $w) {
//Add your code for this event here:
var bases = ("C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B")
var extensions = ("7", "6", "7b5", "9", "add9", "sus4", "sus2", "11", "13", "Maj7", "Maj9", "Maj13", "7b9", "aug", "7#5",
"7Alt", "7#11", "9#11", "13#11", "dim", "dim7", "min", "min7", "min11", "min13", "min6", "min7b5", "7#9")
var chord = "your progression: \n"
var i
for (i = 1; i <= 4; i++) {
// Définir un nombre random selon la longueur du tableau
var numBase = Math.floor(Math.random() * Math.floor(bases.length))
var numExt = Math.floor(Math.random() * Math.floor(extensions.length))
chord += bases(numBase)
chord += extensions(numExt)
chord += "\n"
}
$w('#text27').text = chord
}

When I test it, nothing happens in the textbox. There is no debug function so I cannot see where exactly something goes wrong.

Can anybody see where I failed?

Thank you very much and have a nice day! :slight_smile:

Your arrays are not written properly, an array uses [ ]: this should be your issue

var bases = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]

var extensions = ["7", "6", "7b5", "9", "add9", "sus4", "sus2", "11", "13", "Maj7", "Maj9", "Maj13", "7b9", "aug", "7#5",
"7Alt", "7#11", "9#11", "13#11", "dim", "dim7", "min", "min7", "min11", "min13", "min6", "min7b5", "7#9"]

Try this as well

var numBase 
var numExt

for (i = 1; i <= 4; i++) {
// Définir un nombre random selon la longueur du tableau

numBase = Math.floor(Math.random() * Math.floor(bases.length))
numExt = Math.floor(Math.random() * Math.floor(extensions.length))
chord += bases(numBase)
chord += extensions(numExt)
chord += "\n"
}