[ZPT] ZPT, Javascript

Chris Withers chrisw@nipltd.com
Wed, 19 Mar 2003 16:12:55 +0000


That's probably the best way...

cheers,

Chris

Tom Deprez wrote:
> okay,
> 
> This is a way, please let me know if there is a better way:
> 
> The Python script part  (getSelectArray):
> 
> items = []
> 
> campi = context.sql_getCampi()
> for campus in campi:
>   places = context.sql_getPlacesByCampus(ACampus = str(campus.campus))
>   row = []
>   for place in places:
>     row.append(place.plaats)
>   items.append(row)
> 
> return "SelectArray="+str(items)
> 
> The javascript part:
> 
> <script type="text/javascript"
>         tal:content="python:here.getSelectArray()">
> </script>
> 
> <script type="text/javascript">
> function updatePlacesList(theForm) {
>   var NumPlace = theForm.field_PlaceSelect.options.length;
>   var SelCampus = 0;
> 
>   while(NumPlace > 0) {
>     NumPlace--;
>     theForm.field_PlaceSelect.options[NumPlace] = null;
>   }
> 
>   SelCampus =
> theForm.field_CampusSelect.options[theForm.field_CampusSelect.selectedIndex]
> .value;
> 
>   if (SelCampus > 0)
>   {
>     NumPlaces = SelectArray[SelCampus].length
> 
>     for (i=1; i<=NumPlaces; i++)
>     {
>       theForm.field_PlaceSelect.options[i] = new
> Option(SelectArray[SelCampus][i-1],SelectArray[SelCampus][i-1])
>     }
>     theForm.field_PlaceSelect.selectedIndex=1
>   }
> 
> }
> </script>
> 
> 
> Regards,
> Tom
> 
>