[Zope] Loading Javascript Arrays with ZSQL Method

J Cameron Cooper jccooper@jcameroncooper.com
Wed, 05 Feb 2003 14:47:40 -0600


>
>
>It is possible to load a Javascript array using data from a ZSQL Method?
>Maybe some of you can give me a better way of doing this without using 
>Javascript.
>
Not at run-time, of course, but it's quite simple to do, say in Page 
Templates...

<html>
...
<script ...>
..
js_array = [
   <span tal:repeat="array_elt container/sql_method" tal:omit-tag="">
       <span tal:replace="array_elt">1</span><span 
tal:condition="not:repeat/array_elt/end" tal:omit-tag="">, </span>
   </span>]
..
</script>
..
the rest of your page
</html>

Or a similar thing in DTML. (I have to jump through a few hoops in PTs 
because the output can't be XMLish.)

You'll pardon me if this isn't what a JavaScript array looks like. I 
didn't bother to look it up.

>I just want to create a dynamic drop down menu that users can select from and 
>be able to display contents gather from a database query according to their 
>selection.  For example,  if a user select category A.  Then it will display 
>all items for category A pulled from a database column.  if select category 
>B, then display all B items, etc.
>  
>
You should take a look at how it's done with CSS. See

http://www.meyerweb.com/eric/css/edge/menus/demo.html

It's easy enough to generate the unordered list of links it uses to make 
the menus. It only works in Mozilla-based browsers at the moment, though 
you might be able to find more general ones if you look more than I did.

          --jcc