1

I have an HTML file with multiple 'select' - each select corresponds to one match of tournament round (eg - for winner there is one select with 'winner' class, for final there are two selects with 'final' class, for semis are four selects with 'semi-final' class and so on). To each select in html I have got 'onchange' parameter provided, like that:

<select onchange="previousRounds()" name="winner" class="winner">

I know that if one select will be changed by JS code it won't trigger onchange parameter. So at the end of my function I put:

get_previous_round[j].onchange();

As I browsed through the I figured it should trigger function that I provided in onchange parameter in "get_previous_round[j]" (this is just a variable that corresponds to one my selects), but it throws an error:

'Cannot read property 'onchange' of undefined at previousRounds'.

I also tried it in console:

console_try = document.getElementsByClassName('final')
console_try[0].onchange()

but the same error occured.

Am I missing something?

Sygol
  • 167
  • 2
  • 8
  • It would be `get_previous_round[j].change();`, not `get_previous_round[j].onchange();`. But the error message tells us that you're not getting that far, because `get_previous_round[j]` is `undefined`. You haven't given us enough code, but see the linked question's answers for the overwhelmingly-likely reason for that. – T.J. Crowder Jul 23 '19 at 16:56
  • But when I type it in console, as I wrote in post, my 'console_try[0]' returns – Sygol Jul 23 '19 at 17:08

0 Answers0