Again: Confused

I am loading a <select> via Ajax and put it in an element (rectangle) via innerHTML. That Select should call a function inside Hype via onChange='xyz()' - but I get the error 'xyz is not defined'.

What am I missing here? Spelling is checked :slight_smile:

the scope does not fit ... should help:

1 Like

As the solution is meant for single Hype widgets (meaning only works if there is not more than one Hype document on a webpage), to get a hypeDocument solution for a multi Hype widget setup, here is a quick insight in what is going on behind the scenes. Hype actually has a global lookup of all the Hype widgets on a page, and it can be found under HYPE.documents (← check it out in your browser console). Under that JavaScript object, every hypeDocument is listed by its document ID, and that is in turn based on its document name. There in lies the challenge of hard-coding as it introduces the dependent on your Hype document name. Hence, renaming your document would lead to refactoring your hard-coded links and another quirk with this lookup is that when you only preview in Hype, the preview mode doesn't use the document name (hence ID) you assigned it, but calls it index.

Hence, the above workaround of capturing the local hypeDocument on the event Hype Document Load and assigning it to a global variable called hypeDocument. As this event fires for every Hype widget on a page, you can see how this could fail in such a scenario. The moment you have more than one Hype widget on a page, the last one initialized will populate the global hypeDocument produced by this method and might lead to some unintended behavior. This solution is viable and shouldn't be a problem as long as one can be sure that there is only one Hype widget on a page or all are running from within iFrames.

Don't get me wrong the lookup is still a valuable thing, although using it directly, through hard-coding can be challenging. One initial workaround was to auto-detect the hypeDocument from withing a rectangle:

If you are a Hype Actions Event user, you can also simply use action events to capture change using data-change-action and map it to a function or direct JavaScript as seen here:

OK - thanks again.
I've put that getHypeDocument-Script in the Head-HTML and the snippet to retrieve the document as a script in a rectangle - as proposed.

But then I get this in console:

APPLY ERR w=<script>
	var hypeDocument=getHypeDocument();
</script>

 : ReferenceError: getHypeDocument is not defined

(Spelling really checked)
What am I doing wrong?

jfyi: it's proofed good praxis to offer a simple Hypefile showcasing an issue. Makes it easier for everyone :slight_smile:

Sorry. You are right - here is the corresponding hype-file. Don't know if it works without the php-files though ...
weltreise61.hype.zip (1.7 MB)

Here is an example…

Funny, we posted at the same time. BTW if the previous solution worked … keep it.
It just fails when you have more than one Hype document on your page.

1 Like