[Zope] surprising interaction between Javascript and Zope

Phillip Hutchings sitharus at gmail.com
Tue May 24 19:27:48 EDT 2005


On 25/05/05, Dennis Allison <allison at shasta.stanford.edu> wrote:
> 
> We have a need to set a session variable concurrently with a
> user submitting a form on a mouse click.  I accomplish this with
> a bit of JavaScript associated with the OnClick attribute of the
> form:
> 
>   location.replace('/setSesVar?var=nams&val=xxx;frm.submit();
> 
> which does the job except that the setSesVar script is executed twice, a
> fact we discovered by monitoring calls to the setSesVar script.  Once with
> an incorrect parameter, and secondly with a correct parameter.
> 
> There is probably some obvious explanation, but I am stumped.  Setting
> invalid values into session variables, even transient invalid values, can
> cause problems.

That JavaScript will never work properly. What you're doing is telling
the browser to go to a new page, then submit the form. However, the
form is no longer there, because you're on the new page. The behaviour
you're seeing is probably caused by the browser getting completely
confused.

Why aren't you doing this in the server side script that the form
calls? It makes more sense to do it that way.

If you insist on doing it the current way you'll need to use a hidden
iframe and load the page there, or use XmlHttpRequest to perform a
subrequest.
-- 
Phillip Hutchings
http://www.sitharus.com/
sitharus at gmail.com / sitharus at sitharus.com


More information about the Zope mailing list