W3C home > Mailing lists > Public > www-forms@w3.org > January 2007

Re: setting xforms control value with javascript

From: Dustin Whitney <dustin.whitney@gmail.com>
Date: Tue, 16 Jan 2007 12:47:14 -0700
Message-ID: <23def8000701161147vbb5636aw13d4d2a40887d9bd@mail.gmail.com>
To: "Iņaki Salinas Bueno" <inksalinas@gmail.com>
Cc: www-forms <www-forms@w3.org>
Heh, I was working on the same thing yesterday.  Here is a simple version of
what I accomplished, and probably what you are looking for.

<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:event="http://www.w3.org/2001/xml-events">
    <head>
        <script language="javascript">
        <![CDATA[
            function changeMe(){
                var model = document.getElementById("myModel");
                 var instance = model.getInstanceDocument("myInstance");
                 var textElements = instance.getElementsByTagName("text");
                 textElements[0].firstChild.nodeValue = 'Changed!';
                model.rebuild();
                model.refresh();
            }
        ]]>
        </script>
        <xforms:model id="myModel">
            <xforms:instance id="myInstance">
                <text xmlns="">Change Me!</text>
            </xforms:instance>
            <xforms:instance id="script">
                <script url="javascript:changeMe()"/>
            </xforms:instance>
        </xforms:model>
    </head>
    <body>
        <xforms:input ref="/text"/>
        <xforms:trigger>
            <xforms:label>Change!</xforms:label>
            <xforms:load resource="javascript:changeMe()"
event:event="DOMActivate"/>
        </xforms:trigger>
    </body>
</html>

-Dustin


On 1/16/07, Iņaki Salinas Bueno <inksalinas@gmail.com> wrote:
>
> Hello,
>
> I'm trying to set the value of an xforms control using JavaScript: I must
> use a JavaScript function, and set the result in the form.
>
> I call the Javascript function following a tip<http://www-128.ibm.com/developerworks/xml/library/x-xformstipcalljs/index.html>of Nicholase Chase from IBM (using 'load'), and it works.
>
> I want to use this function:
>
>       document.getElementById('docPKCS7').value = crypto.signText (
> document.getElementById('formulari').innerHTML, "auto");
>
> 'docPKCS7' must point to xforms control. The right part of the equality
> works, but the allocation of the value obtained to the object pointed by
> 'docPKCS7' not.
>
> This is the code of the xforms control:
> <xforms:textarea bind="docPKCS7">
>
> I tried this too:
> <xforms:textarea ref="instance('auxiliars')/aux:ajudes/aux:solicitutPKCS7"
> id="docPKCS7">
>
> And, following some advices from this post
> <http://www.mail-archive.com/orbeon-user%2540lists.sourceforge.net/msg01020.html>,
> I introduce the xhtml:id attribute:
> <xforms:textarea ref="instance('auxiliars')/aux:ajudes/aux:solicitutPKCS7"
> xhtml:id="docPKCS7">
>
> But nothing works. The javascript console don't show any problem or
> warning, except using xhtml:id that appears the following:
> Error: document.getElementById("docPKCS7") has no properties
>
> However, the problem is the allocation of the value in the xforms control
> because using a HTML textarea it works (the value returned by the function
> appears in the textarea):
> <textarea id="docPKCS7" rows="5" cols="50"/>
>
> Maybe my problem is related to a namespace conflict (like this<http://mail-archive.objectweb.org/ops-users/2006-04/msg00267.html>),
> but in that case I don't know how to attack it.
>
> Where is the problem? What other things I can test?
> Lot of thanks
>
> Iņaki
>
>
>
>
>
>
>
Received on Tuesday, 16 January 2007 19:47:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:08 GMT