Hello.

I try to make a certain functionality for convenience of the organization of dependent drop-down lists.

Those. So as not to copy the same code, which will have only different names.

In general, this is not what the jsfiddle example

Especially on jsfiddle to make it clear.

The changeSelectList function apparently takes three parameters.

  1. id from the first select (not important in this case)
  2. select_value is the ID that will be in the second selection in option value
  3. select_name is the name that will be in option

If I do in each

 sselect.append('<option value="'+this.type+'">'+this.color+'</option>'); 

Where type and color (these are keys in an array), then all the rules and it displays to me as expected.

If I try to use function arguments

 sselect.append('<option value="'+this.select_value+'">'+this.select_name+'</option>'); 

then in response I get undefined . I understand very little in JS, do not be angry)

Nagulyulsya why does not work did not work.

I would be grateful for the help.

  • you looked at what this is equal to, this is an array element from json, it’s not very clear what you are trying to do, and what this.type doesn’t like - zb '
  • so need ? - zb '
  • Yes. I did not think at all about square brackets. Thank you very much @eicto Please create an answer, I will choose - drop_off

1 answer 1

Apparently, you need to choose the value of this , based on the value of select_value in js, this is done by square brackets - this[select_value]

  • Thanks for the help. - drop_off pm