You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Stewart, Gary" <Ga...@luht.scot.nhs.uk> on 2006/02/13 12:38:47 UTC

Using External Javascript in CForms

Hi there,

I've been trying to use an external Javascript in an on-value-changed in a form field def.

I have something like:

<fd:on-value-changed>
  <fd:javascript>
     event.source.value = formatDate(event.source.value);
  </fd:javascript>
</fd:on-value-changed>

and I include the function in one of the stylesheets. I get a org.mozilla.javascript.EcmaError: "formatDate" is not defined; which is quite right as it hasn't been defined at that stage. I looked through the samples but I couldn't see anywhere were an external Javascript was included for this purpose. Can this be done or should all scripting be performed inline?

Thanks,

Gary

*****************************************************************
The information contained in this message may be confidential or 
legally privileged and is intended for the addressee only, If you 
have received this message in error or there are any problems, 
please notify the originator immediately. The unauthorised use, 
disclosure, copying or alteration of this message is 
strictly forbidden.
*****************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using External Javascript in CForms

Posted by Robin Wyles <ro...@robinwyles.com>.
Gary,

You can add a reference to the JS file containing your formatDate  
function in the sitemap...

<map:flow language="javascript">
	<map:script src="flow/date_utils.js"/>
</map:flow>

... or you could include it in one of your existing flowscript files  
like this ...

cocoon.load("flow/date_utils.js");

The advantage I see to declaring it in the sitemap is that your JS  
file will be automatically updated when it changes, whereas if you  
include it in another JS file you have to touch the parent file  
before updates to the included file take effect.


Robin

On 13 Feb 2006, at 12:38, Stewart, Gary wrote:

> Hi there,
>
> I've been trying to use an external Javascript in an on-value- 
> changed in a form field def.
>
> I have something like:
>
> <fd:on-value-changed>
>   <fd:javascript>
>      event.source.value = formatDate(event.source.value);
>   </fd:javascript>
> </fd:on-value-changed>
>
> and I include the function in one of the stylesheets. I get a  
> org.mozilla.javascript.EcmaError: "formatDate" is not defined;  
> which is quite right as it hasn't been defined at that stage. I  
> looked through the samples but I couldn't see anywhere were an  
> external Javascript was included for this purpose. Can this be done  
> or should all scripting be performed inline?
>
> Thanks,
>
> Gary
>
> *****************************************************************
> The information contained in this message may be confidential or
> legally privileged and is intended for the addressee only, If you
> have received this message in error or there are any problems,
> please notify the originator immediately. The unauthorised use,
> disclosure, copying or alteration of this message is
> strictly forbidden.
> *****************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org