Hi there,
I'd be very grateful for some help as i'm stuck again!
I am using MiServer. I have an APL boolean in my Compose function. I need to refer to it from within a scripted section for a conditional action. I've tried along the lines below:
dark← 6 ∊ darklist
Add _.script ScriptFollows
⍝var darknew = document.getElementById ('dark');
⍝ if (darknew) {
⍝....
⍝....
⍝ }
Both of the variables (dark and darknew) appear to be recognised as existing in the scripted section. However it always seems to contain a zero value. The code works fine if I assign the variable value within the scripted section (⍝var darknew = 1)
Many thanks, Jinny
Referring to Boolean from 'script' section
-
- Posts: 33
- Joined: Fri Oct 12, 2018 3:05 pm
Re: Referring to Boolean from 'script' section
So the web page (and therefore the Javascript) doesn't automatically pick up APL variables from the workspace, they need to be retrieved from the server. In the case of , you are assigning a JS variable "darknew" the value 1. However, using doesn't create an html element with ID "dark".
One way to get the value of APL's "dark" into your web page is to construct a javascript statement as an APL text vector. I misread at first and thought you wanted darklist in there. If you want to pass a list to Javascript, use ⎕JSON to format the list properly.
In the code below, the title displays "My App" unless you remove the line "dark←0", in which case the title displays "darknew works".
Code: Select all
⍝var darknew = 1
Code: Select all
dark←6∊darklist
One way to get the value of APL's "dark" into your web page is to construct a javascript statement as an APL text vector. I misread at first and thought you wanted darklist in there. If you want to pass a list to Javascript, use ⎕JSON to format the list properly.
In the code below, the title displays "My App" unless you remove the line "dark←0", in which case the title displays "darknew works".
Code: Select all
∇ Compose
:Access Public
'title'Add _.h1 'My App'
darklist←6 6 4 10 5 3 1 10 1 6
dark←6∊darklist
dark←0
script←'var darknew = ', dark,';'
script,←'console.log("test");'
Add _.script script
Add _.script ScriptFollows
⍝if (darknew) {
⍝console.log("darknew");
⍝document.getElementById("title").innerHTML = "darknew works";
⍝}
∇
Re: Referring to Boolean from 'script' section
Many thanks. I haven't managed to get it to work yet - but still experimenting with fresh optimism!
Re: Referring to Boolean from 'script' section
Hooray, it's working.
However, I thought that it might be useful for other readers to know why it didn't work immediately. For some reason, cutting and pasting the lines failed but when I typed them on from scratch they were fine.
Thank you again!
However, I thought that it might be useful for other readers to know why it didn't work immediately. For some reason, cutting and pasting the lines failed but when I typed them on from scratch they were fine.
Thank you again!