Login  Register

Calling Javascript-defined functions from XForms.

Posted by Franclin Foping on Jan 20, 2010; 5:52pm
URL: https://discuss.orbeon.com/Calling-Javascript-defined-functions-from-XForms-tp1018632.html

Hi All,
  I am trying to call a javascript function from XForms but to no avail.
  Here is the issue : How to pass some parameters to a Javascript function from XForms?
 Let us consider the following JS function:
 function myfunction(par1, par2){
  alert('You have entered' + par1 + par2 );
  //Display a Google Map by passing par1 to it.
 }

 Parameters par1 and par2 will be the result of an XPath expression computed by XForms. Ideally, it would be called from XForms like this:
 <xf:trigger>
  <xf:load ref="link that contain the javascript function myfunction"  ev:event="DOMActivate">
 </xf:trigger>


 As far as I know (I may be wrong, though), the only way to call JS functions from XForms is by using the load method and call the JS function as an external resource.
 This topics has already been touched on in an article in IBM's DeveloperWorks that is located here:
 http://www.ibm.com/developerworks/xml/library/x-xformstipcalljs/index.html
 The bottom line is that no parameter is passed to the function which is thus not of great help in my case.
 This problem has also been touched on here http://wiki.orbeon.com/forms/projects/client-side-api-for-custom-javascript-widgets but again it is not implemented.
 So here are my questions:
 1 - How to pass some parameters to a JS method from XForms?
 2 - Is this feature implemented in XSLTForms?
 Finally it might be interesting to point that when I try to specify the name of the JS method directly in the ref attribute of the load element, XSLTForms raises an exception by saying that "Function http://www.w3.org/2005/xpath-functions myfunction() not found" which makes me think that XSLTForms considers the JS function as an XPath function. How to tell XSLTForms that it is actually a JS function?
 In order to reproduce this case I did this:
 <xf:load ref=<a class="moz-txt-link-rfc2396E" href="javascript:myfunction(number(par1),string(par2))">"javascript:myfunction(number(par1),string(par2))" ev:event="DOMActivate"/>  
 I am anxiously waiting for your reply.
 Regards,
 Franclin.

--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws