View previous topic :: View next topic
|
Author |
Message |
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
Hi,
I've read a number of posts and some topics about javascript and rexx co-existing together. And, I've written a very basic rexx program that uses some simple html and javascript.
What I'm trying to do, presuming it can be done and I just don't know the magic, is reference a global variable defined in javascript within the rexx program.
The javascript and rexx command I've defined both reside in the same program. For example
say '<script language="javascript" type="text/javascript">'
say '{var counter = 2}'
say '</script>'
say '<script language="javascript" type="text/javascript">'
say 'function myTest()',
'{alert(counter)}'
say '</script>'
say counter
In the above example, the global variable counter is assigned a value of 2, and will display that value when function myTest() is executed. However, the Rexx command which follows say counter only displays the word COUNTER.
If this can be done, would someone educate me on how this can be accomplished? Thanks in advance. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
Don't you miss some semicolon in your code, do you? |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2583 Location: Silicon Valley
|
|
|
|
Jeff, can you cite a reference for this? I would like to try it out. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2583 Location: Silicon Valley
|
|
|
|
I do not know anything about this. This is all guessing, hypothesis and conjecture:
In your example, it seems like the rexx would run on the web server and it will build an HTML file that will run sometime later on the browser system. I think all of the rexx will run before any of the javascript is run.
That is, in your example rexx, it only has several SAY instructions which are used to compose the HTML file but there is no other execution going on. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2583 Location: Silicon Valley
|
|
|
|
It is not clear what myTest() is... is that also a rexx program? |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
Pedro wrote: |
It is not clear what myTest() is... is that also a rexx program? |
it should be seen as the JS function. But I doubt that REXX can also run JS code..
Code: |
function myTest() {alert(counter)}; |
*afaik* |
|
Back to top |
|
|
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
Hi Pedro and Joerg,
Thanks for your replies, let me respond:
"Can you cite a reference for this? I would like to try it out"
-- I don't have a reference for you, sorry. The code I wrote is from other systems that were written using Rexx. It's been trial and error as I read about javascript and HTML, then incorporate it into Rexx.
In your example, it seems like the rexx would run on the web server and it will build an HTML file that will run sometime later on the browser system. I think all of the rexx will run before any of the javascript is run.
That is, in your example rexx, it only has several SAY instructions which are used to compose the HTML file but there is no other execution going on.
-- Yes, I'm using Rexx on a webserver executing under USS. You may be right in that Rexx statements execute first before the javascripts get invoked. I don't know how it all works behind the scenes either. The "say" statements are executing. Because I do see the webpage with my objects displayed, and when I click on them, they execute the function I specified.
It is not clear what myTest() is... is that also a rexx program?
-- That is a javascript function. All it does is displayed the value of counter. And it works, so that is how I know the variable counter has been populated.
It should be seen as the JS function. But I doubt that REXX can also run JS code.
-- You may be right in that Rexx may not run the JS code, but the webserver is. Rexx cgi-script I think just allows the code to be generated so javascript can execute it.
As I mentioned in my opening comment, it may not be possible to reference a javascript variable or HTML object from Rexx. But wanted to check just the same. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2583 Location: Silicon Valley
|
|
|
|
Quote: |
it may not be possible to reference a javascript variable or HTML object from Rexx |
You are in control of the entire thing. You could do something like this:
Code: |
counter=2
say '<script language="javascript" type="text/javascript">'
say '{var counter = 'counter'}'
say '</script>'
say '<script language="javascript" type="text/javascript">'
say 'function myTest()',
'{alert(counter)}'
say '</script>'
say counter
|
But I think that is not what you want. You probably want to get an updated value from the user/browser to the server.
I think you will need to issue cgi-script POST statement to get information from the browser to the server. |
|
Back to top |
|
|
|