Behalf Of Asad Habib
Does anyone know of any resources that describe the use of Javascript within Zope? In particular, I am trying to call a Javascript function using the onChange event handler that is tied to a HTML select element. I need this Javascript function to perform an SQL query and then have it populate another HTML select element with the result set. Is this possible within Zope considering that queries are performed by Z SQL methods and possible other factors that I am unaware of? Any help would be greatly appreciated. Thanks.
A javascript function executed within a web page cannot influence anything that Zope does, because by the time that the javascript executes in the browser, Zope has alread finished producing the page. The javascript action is local to the browser. How you do it is to have your onChange handler submit a form to Zope. That form should invoke a document, methods, etc., on Zope that will construct the response you want (including any database access), and return it to the browser. Of course the new page will replace the old one, just as for any other form submission. If you do not want to replace the previous page, things get harder. You generally would use frames (possibly an Iframe), and send the form's result to one of the other frames. Then you would use javascript to transfer the data from the frame that received it to the frame with the re-populated select list. The main problem here is to know when the data has been completely received - of course you do not want to try to transfer it before transmission is complete. You can do this with the javascript equivalent of a wait command, but it can be a bit tricky to get right. Or, if you data set is not too large, you may be able to build javascript data stsructures for all the relevant data in the original page. Then you can repopulate the select list without sending a form back to the server. Cheers, Tom P