Groups > IBM > ibm.software.speech.multimodal > Re: dialog actvation from javascript




dialog actvation from javascript

dialog actvation from javascript
Thu, 11 Jan 2007 14:35:25 +010
Hi all,
I need to know how to activate a voice form
from javascript, anybody can help me?

Thanks in advantage.
Antonella.



Post Reply
Re: dialog actvation from javascript
Thu, 11 Jan 2007 18:36:26 +020
Le Thu, 11 Jan 2007 15:35:25 +0200, Nella  
<antonella_santangelo@NOSPAMhotmail.com> a écrit:

> Hi all,
> I need to know how to activate a voice form
> from javascript, anybody can help me?
>
> Thanks in advantage.
> Antonella.

Hello Antonella!

I have solved a similar problem in one of my local projects.

I had two Voicexml forms: #vxform1 and #vxform2. The first was activated  
on page load with an XML Event listener. For the second form I did setup a  
secondary event listener on body which activated #vxform2. Here's the  
simplified code:

<head>

   <vxml:form id="vxform1">
     ...
     <vxml:if cond="someJSfunction()">
       <vxml:throw event="goVxform2" />
     </vxml:if>
     ...
   </vxml:form>

   <vxml:form id="vxform2">
     ...
   </vxml:form>

   <ev:listener observer="the-body" handler="#vxform2"
event="goVxform2" />

</head>

<body id="the-body" ev:event="load"
ev:handler="#vxform1">

   <p>...</p>

</body>

In the above code you can see #vxform1 is activated on page load. Based on  
any form logic you want (tied to JS, any functions you want), you can  
activate #vxform2. You throw the event "goVxform2" and the listener  
observer=#the-body will "catch" it, and activate #vxform2.

This worked for me.

However, in your case, you may not have #vxform1, and you might want to  
activate #vxform2 directly, without any help from other VXML forms. I have  
not tested this method, but it might work. Here's a sample code (untested):

<head>

   <script>
     function someFlower(flower)
     {
       if(flower != 'lily') return false;

       var evt = document.createEvent('HTMLEvents');
       evt.initEvent('goVxform2', false, true);
       document.body.dispatchEvent(evt);

       return true;
     }
   </script>

   <vxml:form id="vxform2">
     ...
   </vxml:form>

</head>

<body ev:event="goVxform2" ev:handler="#vxform2">

   <p>...</p>

   <p><a href="#"
onclick="someFlower('lily')">Click me!</></p>
   <p><a href="#"
onclick="someFlower('rose')">Click me too!</></p>

   <p>...</p>

</body>

How the above works:

1. You have an event listener on <body>. This listener will activate  
#vxform2 only if event "goVxform2" is thrown.
2. You have in your page some buttons which call your JS function, on  
click.
3. You want your function to activate #vxform2 only if the argument is  
correct (in this case "lily"). If flower=='lily' we createEvent of
type  
HTMLEvents. We initEvent('goVxform2') and then we dispatchEvent() on body,  
where we have the listener. This should activate #vxform2.

That's all theory. I have not tested this code. Hopefully, it works, with  
a little bit of tweaking.

Things to note:

1. Try document.createEvent('Event') - maybe HTMLEvents does not work in  
this case.
2. Try other initEvents. Maybe Opera does not allow initializing and  
dispatching of custom events. If this is the case, try known events, such  
as click.
3. The event listener can be setup directly on <body> (as in the above  
code sample), or as an independent event listener (as in the first code  
example).

If the above works, it should not be hard at all to integrate this into  
your pages.

VoiceXML Event Handling:
http://www.w3.org/TR/voicexml20/#dml5.2

XML Events:
http://www.w3.org/TR/xml-events/

DOM document.createEvent:
http://developer.mozilla.org/en/docs/DOM:document.createEvent

That's about all. Good luck!



-- 
ROBO Design - We bring you the future
Post Reply
Re: dialog actvation from javascript
Wed, 07 Feb 2007 16:48:06 -050
Nella wrote:
> Hi all,
> I need to know how to activate a voice form
> from javascript, anybody can help me?
> 
> Thanks in advantage.
> Antonella.
> 
> 
> 
> 
To activate a VoiceXML form with id="vForm" try the following:

      var e = document.createEvent("UIEvents");
      e.initEvent("DOMActivate","true","true");
Post Reply
Re: dialog actvation from javascript
Wed, 21 Feb 2007 18:30:30 +010
Thanks to everybody!!
It works.


"Gerald McCobb" <mccobb@us.ibm.com> ha scritto nel messaggio 
news:eqdhen$1mk2s$1@news.boulder.ibm.com...
> Nella wrote:
>> Hi all,
>> I need to know how to activate a voice form
>> from javascript, anybody can help me?
>>
>> Thanks in advantage.
>> Antonella.
>>
>>
>>
>>
> To activate a VoiceXML form with id="vForm" try the following:
>
>      var e = document.createEvent("UIEvents");
>     
e.initEvent("DOMActivate","true","true");
>      document.getElementById("vForm").dispatchEvent(e); 

Post Reply
about | contact