Hi guys,
This is a small snippet of code to show how to create an array of textboxes and sliders etc.
Code: Select all// Declare the arrays of textboxes and sliders here so they can be accessed globally
var txtTextbox= [];
var sldSlider = [];
main();
function main(){
var pnlPanel = [];
var grpGroup = [];
dlg = new Window ("dialog");
// Add a panel and create the input controls
for (var i = 0; i < 5; i++){
pnlPanel = dlg.add('panel', undefined, 'Panel ' + (i + 1) + ':');
grpGroup = pnlPanel.add('group');
txtTextbox = grpGroup.add('edittext', undefined, '0');
txtTextbox.preferredSize = [50,20];
txtTextbox.justify = 'right';
txtTextbox.text = 0;
sldSlider = grpGroup.add('slider', undefined, 0, 0, 100);
}
// Show the window
dlg.center();
dlg.show();
return;
}
Note: If the textboxes and sliders are to be accessed from another function it is required to delcare them as global variables.
For some reason arrays of textboxes, sliders etc don't seem able to be referenced as children of another object (eg. dlg.txtTexbox)
I'm still not quite sure how to assign event handlers to the controls dynamically, within the 'for loop'
This doesn't work:-
Code: Select alltxtTextbox[i].onChange = function () { sldSlider[i].value = Number(txtTextbox[i].text); };
You just have to assign each one individually:-
Code: Select alltxtTextbox[0].onChange = function () { sldSlider[0].value = Number(txtTextbox[0].text); };
Hope someone may find this helpful,
- Michael B
Create arrays of textboxes etc
Re: Create arrays of textboxes etc
I found the solution for assigning values dynamicly
Code: Select all
for (var i = 0; i < 5; i++){
txtTextbox[i].onChange = function () {
for (var k = 0; k < 5; k++){
sldSlider[k].value = Number(txtTextbox[k].text); }
}
}
Re: Create arrays of textboxes etc
After 5 years and 5 days?! It had to be long travel thru scripting lands
I'm joking, I'm learning and that is amazing news to me. Could you please show us how to implement that snippet to your earlier code that it really work dinamically, Thank You!

I'm joking, I'm learning and that is amazing news to me. Could you please show us how to implement that snippet to your earlier code that it really work dinamically, Thank You!