I have source code that someone original wrote in javascript and which I'm attempting to get running in Zope by replacing the javascript code with DTML and an external python method but my code does not work. The HTML/DTML code looks like this: <SELECT name="myselect" onchange=<dtml-var expr="select_handler(value)"> > <OPTION value="choice1">choice1</OPTION> <OPTION value="choice2">choice2</OPTION> <OPTION value="choice3">choice3</OPTION> </SELECT> Question 1: Should this work? Question 2: Does it make sence to change the client side javascript code with server side DTML? It seems like it may be better to let the javascript code deal with the selection for efficiency. Jim
From: "Jim Anderson" <ezjab@ieee.org>
I have source code that someone original wrote in javascript and which I'm attempting to get running in Zope by replacing the javascript code with DTML and an external python method but my code does not work.
The HTML/DTML code looks like this:
<SELECT name="myselect" onchange=<dtml-var expr="select_handler(value)"> > <OPTION value="choice1">choice1</OPTION> <OPTION value="choice2">choice2</OPTION> <OPTION value="choice3">choice3</OPTION> </SELECT>
Question 1: Should this work?
It won't work. The 'onchange' function is a browser based event and the browser does not know anything about server-side (ie. zope) functions, variables, etc.
Question 2: Does it make sence to change the client side javascript code with server side DTML? It seems like it may be better to let the javascript code deal with the selection for efficiency.
I would stick with js for anything that you want to control while 'in' the user's browser (ie. handle browser-based events like onmouseover, etc). Anything that has to do with saving/storing/updating information in an permanent/semi-permanent manner should be done on the server. For example: use js to let the user select data and perform any data edits/checking you want, then send the data to the server (zope) for storage. HTH Jonathan
Thank you, Jonathan. Your response does help some. I have a follow up question, being a newbie. How does information get passed from javascript back to the my server side environment when using Zope? Just a pointer on where to look will be helpful. Jim Small Business Services wrote:
From: "Jim Anderson" <ezjab@ieee.org>
I have source code that someone original wrote in javascript and which I'm attempting to get running in Zope by replacing the javascript code with DTML and an external python method but my code does not work.
The HTML/DTML code looks like this:
<SELECT name="myselect" onchange=<dtml-var expr="select_handler(value)"> > <OPTION value="choice1">choice1</OPTION> <OPTION value="choice2">choice2</OPTION> <OPTION value="choice3">choice3</OPTION> </SELECT>
Question 1: Should this work?
It won't work. The 'onchange' function is a browser based event and the browser does not know anything about server-side (ie. zope) functions, variables, etc.
Question 2: Does it make sence to change the client side javascript code with server side DTML? It seems like it may be better to let the javascript code deal with the selection for efficiency.
I would stick with js for anything that you want to control while 'in' the user's browser (ie. handle browser-based events like onmouseover, etc). Anything that has to do with saving/storing/updating information in an permanent/semi-permanent manner should be done on the server.
For example: use js to let the user select data and perform any data edits/checking you want, then send the data to the server (zope) for storage.
HTH
Jonathan
From: "Jim Anderson" <ezjab@ieee.org>
Thank you, Jonathan. Your response does help some. I have a follow up question, being a newbie.
How does information get passed from javascript back to the my server side environment when using Zope? Just a pointer on where to look will be helpful.
You have to use javascript to insert the variable into a form element which will then be returned to zope. There is a really good tutorial on javascript and how it relates to the Document Object Model (DOM) at: http://www.quirksmode.org/js/ If you are a zope newbie, but have some programming skills then this shouldn't be a problem. However, if you are not a programmer-type I would stay away from this (when you start playing with javascript you have to start worrying about supporting various web browsers - eg. Explorer, Mozilla, Opera, Safari, Netscape, etc - which can be easy or really complex depending on how much functionality you put into the javascript). If you decide you are not going to pursue the javascript option, post your problem on the list and maybe someone can address your specific issue. HTH Jonathan
Jonathan, I spent a good part of the weekend and today experimenting with DTML files laced with javascript. I made quite a bit of progress, but I can't get past a basic communication problem between the javascript environment on the client and the Zope server environment. My current problem is that I'm trying to pass information from js to Zope and I'm doing it through an external method that is called as an action on a form. The client side is putting up a form with a selction in it. The selection determines what the next frame to be posted will be and js procedes to start posting the next frame. The action on the submitted form passed the choice back to the server, and the choice is used by the server to insert information about the choice into the next frame that js is trying to put up in the window. The logic works sometimes, sometimes it doesn't. It looks to me that the code is in a race condition whether it can get the choice information back to the server before the server sends the next frame to the client side. To fix my problem, I need to be able to block js from running while the server gets updated. But I don't see anyway of doing this in javascript. So my real question is, "Is there anyway using javascript to get coordinated communication between the client and server to assure that client and server process can be synchronized when required?" I can definitely work around this issue, but my resulting web pages will be less configurable and will require greater maintenace. I appreciate you thoughts or anyone elses thoughts. Jim Small Business Services wrote:
From: "Jim Anderson" <ezjab@ieee.org>
Thank you, Jonathan. Your response does help some. I have a follow up question, being a newbie.
How does information get passed from javascript back to the my server side environment when using Zope? Just a pointer on where to look will be helpful.
You have to use javascript to insert the variable into a form element which will then be returned to zope.
There is a really good tutorial on javascript and how it relates to the Document Object Model (DOM) at: http://www.quirksmode.org/js/
If you are a zope newbie, but have some programming skills then this shouldn't be a problem. However, if you are not a programmer-type I would stay away from this (when you start playing with javascript you have to start worrying about supporting various web browsers - eg. Explorer, Mozilla, Opera, Safari, Netscape, etc - which can be easy or really complex depending on how much functionality you put into the javascript).
If you decide you are not going to pursue the javascript option, post your problem on the list and maybe someone can address your specific issue.
HTH
Jonathan
From: "Jim Anderson" <ezjab@ieee.org>
So my real question is, "Is there anyway using javascript to get coordinated communication between the client and server to assure that client and server process can be synchronized when required?"
I can definitely work around this issue, but my resulting web pages will be less configurable and will require greater maintenace. I appreciate you thoughts or anyone elses thoughts.
The way I do it is: 1) js function on the client creates a js var: isLoaded and set it to 'false' 2) js function on the client then loads a page from the server 3) the page on the server contains embedded js which sets the same var (isLoaded) to true (note: put this embedded js at the end of the page, or use the onLoad event to cause it to execute when the page is finished loading) 4) the original js routine, running on the client, can check the value of isLoaded in a loop (use setTimeout) until isLoaded is true You can create a generic js function to check page load status as long as you make sure the page from the server updates the a standard js var (ie. isLoaded). HTH Jonathan
participants (2)
-
Jim Anderson -
Small Business Services