[Zope] Changing REQUEST in a javascript

Casey Duncan casey@zope.com
Wed, 18 Sep 2002 13:47:24 -0400


There are a few solutions to the one select populates another problem:

One is to have the first select trigger a form post to Zope, which return=
s the=20
same page with new data in the second select box cooresponding to the=20
selection. This is the easiest to get to work cross-browser and could eve=
n=20
work with Javascript turned off.

Another method is to have Zope put all of the potential choices in the se=
cond=20
select box into the Javascript code that gets sent to the client. You cou=
ld=20
use an associative array to do this. Then populate the second select box =
with=20
the items in that key of the Javascript associative array. This method wo=
rks=20
good only when the total number of items is relatively small in both sele=
cts=20
and doesn't change very often.

A third method would be to use the Virtual Cowboys Javascript XML-RPC lib=
rary=20
to query the server "out of bound" from the client when a selection in th=
e=20
first box was made. The query would ask Zope for the items to put in the=20
second select dynamically. This would work well for any number of select=20
items, and always be up to date. It would only work on recent IE and Mozi=
lla=20
browsers though, because it requires DOM level 3 support.

Another method similar to 3, but not requiring anything more than Javascr=
ipt=20
1.2(?) support and frames is to use a frameset with an invisible frame th=
at=20
you can refresh from the visible frame. The invisible frame would be used=
 to=20
send requests to Zope and receive the Javascript code necessary to popula=
te=20
the second list box.

Which method I chose depends on a few factors:

 How many items will be in each select list
 How comfortable are you with client-side vs. server-side programming
 What browsers you must support
 How dependant you want your application to be on Javascript

hth,

Casey

On Wednesday 18 September 2002 12:53 pm, Dag Nygren wrote:
> > [om: Dag Nygren]
> >=20
> > > I now finally figured out the parameter-passing stuff
> > > and ran into a new problem:
> > > I need to change the REQUEST on the client, presumably
> > > in a javascript
> > >=20
> > > Can this be done and How ?
> > >=20
> >=20
> > There is no such thing.  The browser client has form data that it
> > submits, and the Zope REQUEST object ends up containing the form data=
=2E
> > The client knows nothing about Zope objects.
> >=20
> > Tell us what you really want to accomplish and we will help you work =
out
> > how to do it.
>=20
> Yes, of course, sorry for the a bit naive question. I am new to Zope an=
d
> Phyton and had difficulties getting the right picture in my mind about
> what is going on here.
> Additionally the  Zope way of  "inheriting"  the REQUEST  object=20
> confused me.
>=20
> The original problem was creating a mutiselect form where select#1
> changed the alternatives of Select#2.
> I also did not want the URL to show the parameters.
>=20
> I now figured out that I can use an ONCHANGE=3Ddocument.submit() for
> Select#1 to make the same formpage repeat itself with the changed
> Select#2 attributes.
> Additionally I think (haven't tested yet) that I can submit and alterna=
tive
> attribute in the "real" formsubmit and check for that with <dtml-if> in=
 the=20
> form and then do the intended insert into a database.
>=20
> Please tell me if there is something fundamentally wrong with this  way
> of thinking and if there are easier ways of doing this.
>=20
> Thanks for the answers so far, preserves my fate in the OpenSource comm=
unity=20
!!
>=20
>=20
> --=20
> Dag Nygren                               email: dag@newtech.fi
> Oy Espoon NewTech Ab                     phone: +358 9 8024910
> Tr=E4sktorpet 3                              fax: +358 9 8024916
> 02360 ESBO                              Mobile: +358 400 426312
> FINLAND
>=20
>=20
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>=20