Controlling dropdown list

I have a dropdown list with the following values to change the width and height of images:

  • 320 x 240
  • 640 x 480
  • 800 x 600
  • 1024 x 768
  • 1280 x 720
  • 1920 x 1080
  • 3840 x 2160
  • 5120 x 2880

And I set the width and height values as follows:

	if (dlg.Control("default").value == 0) {
	dlg.Control("new_width").value = 320;
	dlg.Control("new_height").value = 240;
	}

	if (dlg.Control("default").value == 1) {
	dlg.Control("new_width").value = 640;
	dlg.Control("new_height").value = 480;
	}

	if (dlg.Control("default").value == 2) {
	dlg.Control("new_width").value = 800;
	dlg.Control("new_height").value = 600;
	}
			
	if (dlg.Control("default").value == 3) {
	dlg.Control("new_width").value = 1024;
	dlg.Control("new_height").value = 768;
	}

	if (dlg.Control("default").value == 4) {
	dlg.Control("new_width").value = 1280;
	dlg.Control("new_height").value = 720;
	}

	if (dlg.Control("default").value == 5) {
	dlg.Control("new_width").value = 1920;
	dlg.Control("new_height").value = 1080;
	}

	if (dlg.Control("default").value == 6) {
	dlg.Control("new_width").value = 3840;
	dlg.Control("new_height").value = 2160;
	}

	if (dlg.Control("default").value == 7) {
	dlg.Control("new_width").value = 5120;
	dlg.Control("new_height").value = 2880;
	}

But I am wanting to simplify the code with arrays but it doesn't work:

    var width = [320, 640, 800, 1024, 1280, 1920, 3840, 5120];
    var height = [240, 480, 600, 768, 720, 1080, 2160, 2880];
					
    dlg.Control("new_width").value = width.slice(dlg.Control("default").value);
    dlg.Control("new_height").value = height.slice(dlg.Control("default").value);

Use [] to read a specific value from an array, e.g. width[0] would return 320.

1 Like

Perfect @Jon, thank you very much!!!

   dlg.Control("new_width").value = width[dlg.Control("default").value];
   dlg.Control("new_height").value = height[dlg.Control("default").value];
1 Like

I would like item 4 of the list to be selected by default, as I have read in the manual, I must use the "SelectItem" method, but I have not known how to implement it.

SelectItem(dlg.Control("default").value: 4);

It's explained in the docs and you'll find working examples in the forum.

Thank you very much @lxp for your recommendations, I had already done both a long time ago but without success.

According to my interpretation of the manual:

2024-02-13 09 16 24

Was that I did the construction:

SelectItem(dlg.Control("default").value: 4);

But seeing now other examples in the forum, I perceived that the syntax is this:

dlg.Control("default").SelectItem(4);

I had achieved the same result with:

dlg.Control("predeterminados").value = 4;

But when selecting a new item from the list, it did not change. Now with SelectItem I continue without being able to change the value of the list, but the problem is going to be something else, I must be placing that part of the code in the wrong position.

Thank you very much again :grinning:

SelectItem() is a method, not a function. Methods need to be preceded by an object on which they operate. They cannot stand on their own.

If you want to bring your coding skills up to speed, make sure you can properly distinguish all the elements of a script: What's an object? What's a method, a property, a function, a variable? Being able to do so will reduce your guesswork substantially.

1 Like

True @lxp, Leo had already recommended that I study more about JavaScript in general, I sincerely thank all of you!