Opening Modal through Javascript

Hi,

on https://theme.co/docs/toggleable#programmatically it’s described how a modal can be openend programatically. I’ve tried to implement that, but so far, it isn’t working.

The modal settings:
Scherm­afbeelding 2025-06-26 om 22.13.47

The Javascript:

var button = document.getElementById("code-check");
var code_input = document.getElementById("code-input");
var code_correct = 629;

button.onclick = function(){
  var cur_value = code_input.value;
  if(cur_value == code_correct){
    alert("klopt");
    window.xToggleUpdate('modal-code-correct', true)
  }
}

The alert is firing, the modal isn’t. What am I missing here?

Hello @dhunink,

Thanks for writing in! The modal element toggle hash could be the issue. Could you please share the URL of the page where you have applied this JS code so that we can investigate?

Cheers.