Page 1 of 1

ecmascript error on substr attempt

Posted: Wed May 02, 2007 2:32 pm
by vmagic
I want to use substr to pick off the "3" in "13" contained in "quizno" & use it as an index to retrieve & speak the value "four" from the array.

I am getting the following error...

VXI::var_element(name="quiz_ans" expr = "subd.myarray[quizno.substr(1)]")
errmsg TypeError: quizno.substr is not a function line 1 linetxt tokentxt
received event: error.semantic.ecmascript

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
     
        <form id="caller">
                <var name="quizno" expr="13"/>
                <subdialog name="subd" src="#callee">

                </subdialog>
                <block>
                <var name= "quiz_ans" expr="subd.myarray[quizno.substr(1,1)]"/>

                 <prompt>
                               You entered 
                 <say-as type="acronym">
                <value expr="quiz_ans"/>
                  </say-as>         
                  </prompt>      
                </block>
        </form>
        <form id="callee">
                <var name="myarray"/>
                <script>
                        myarray = new Array(4);
                        myarray[0] = 'one';
                        myarray[1] = 'two';
                        myarray[2] = 'three';
                        myarray[3] = 'four';
                 </script>
                <block>
                        <return namelist="myarray"/>
                </block>
        </form>
</vxml>

IVR code needs quotes around text to convert value to string

Posted: Thu May 03, 2007 3:14 pm
by support
Hello,

This IVR error is occuring because you are initializing quizno to the number 13, not the string "13". You should add single quotes around text in the expr attribute of the <var> tag to convert the value into a string:

Code: Select all

<var name="quizno" expr="'13'"/>
After forcing quizno to be initialized as a string you should be able to make use of the substr() method available to all strings.

Regards,
Plum Support