By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

How to capture and alert the value of an xhtml node using JS

P: n/a
hi ;
i have this small code that consist in taking the name of the user and
writing it in the same form as an output.the name is relative to
/data/valid/string1
In my Js code i want to access the value of /data/valid/string1 (The
name seised by the user)
and alert the name as result
Can you help me to achieve this?

<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns="http://xforms.websynapsis.com"
xmlns:books="http://books.websynapsis.com"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xhtml:head>
<xhtml:title>
Test case for primitive XML Schema types
</xhtml:title>

<xhtml:link rel="stylesheet" href="style.css" type="text/css"/>
<xforms:model>
<xforms:instance xmlns="">
<data>
<valid>
<string1
id="f1">Name</string1>
</valid>
</data>
</xforms:instance>
<xforms:bind nodeset="/data/valid/string1"
type="xsd:string" />
</xforms:model>
<xhtml:script id="gtre" type="text/javascript">

function initiate()
{
var p=document.getElementById('label11').firstChild.no deValue
alert(""+p)
}

</xhtml:script>
</xhtml:head>
<xhtml:body>
<xforms:group/>
<xforms:input ref="/data/valid/string1">
<xforms:label lang="en">Name
:</xforms:label>
<xforms:action ev:event="xforms-valid">
</xforms:action>
</xforms:input>

<xhtml:input type="button" value="Afficher"
onclick="initiate();" />
<xforms:group/>

<xforms:output ref="/data/valid/string1" id="label1">
<xforms:label id="label11">Name : </xforms:label>
</xforms:output>
<xforms:group>
</xforms:group>
</xhtml:body>
</xhtml:html>

thanks for any help

Aug 25 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a


sniper wrote:

i have this small code that consist in taking the name of the user and
writing it in the same form as an output.the name is relative to
/data/valid/string1
In my Js code i want to access the value of /data/valid/string1 (The
name seised by the user)
and alert the name as result
If you have XPath support as in Mozilla or as in Opera 9 then this
example should work

<xhtml:input type="button" value="test"
onclick="if (typeof document.evaluate != 'undefined') {
var element = document.evaluate('//data/valid/string1',
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (element != null) {
alert(element.textContent);
}
else {
alert('No element found.');
}
}"/>

But I have no idea in which context or browser you are using that stuff,
mixing XForms (which so far no released desktop browser like IE or
Mozilla has built-in) with script might heavily depend on the browser
and/or XForms implementation/plugin you use. For instance X-Smiles has
excellent XForms support but I have doubts that it has a DOM Level 3
XPath API exposed to script.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 25 '06 #2

P: n/a

Hi Martin Honnen,
Thanks for your reply,this code is working in my browser
but the problem is if i tape a name as an input different from "Name"
the alert message still showing me the same thing "Name"
may be ther's a need of a refresh or somthing like this
thanks;

Aug 25 '06 #3

P: n/a


sniper wrote:

this code is working in my browser
but the problem is if i tape a name as an input different from "Name"
the alert message still showing me the same thing "Name"
may be ther's a need of a refresh or somthing like this
Unless someone else comes along here to help out I suggest you take your
question to a newsgroup or forum dealing with that particular XForms
implementation you are using. The data you are trying to access is
XForms instance data, I don't know currently whether changes the XForms
implementation does to the instance data is supposed to show up directly
in the DOM that is exposed to script.
The XForms newsgroup might also be in a better position to tell whether
you need script at all.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 25 '06 #4

P: n/a
ok thank you Martin for your help

Aug 25 '06 #5

P: n/a
hi all;
this is the solution to my problem, thanks to the help of the xforms
groupe:
the problem was that i used the static instance document from
the xforms document.
I have to use the in-memory version that XForms maintains.
We can get this version by using this:
model.getInstanceDocument(id).
The new code :

<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns="http://xforms.websynapsis.com"
xmlns:books="http://books.websynapsis.com"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xhtml:head>
<xhtml:title>
Test case for primitive XML Schema types
</xhtml:title>

<xhtml:link rel="stylesheet" href="style.css" type="text/css"/>

<xforms:model id="myModel">
<xforms:instance id="myInstance" xmlns="">
<data>
<valid>
<string1 id="f1">Name</string1>
</valid>
</data>
</xforms:instance>
<xforms:bind nodeset="/data/valid/string1" type="xsd:string" />

</xforms:model>

<xhtml:script id="gtre" type="text/javascript">

function affiche()
{
var model = document.getElementById("myModel");
var instanceDoc = model.getInstanceDocument("myInstance");
if (typeof instanceDoc.evaluate != 'undefined') {
var element = instanceDoc.evaluate('//data/valid/string1',
instanceDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue;
if (element != null) {
alert(element.textContent);
}
else {
alert('No element found.');
}
}
}

</xhtml:script>
</xhtml:head>
<xhtml:body>
<xforms:group/>
<xforms:input ref="/data/valid/string1">
<xforms:label lang="en">Name :</xforms:label>
<xforms:action ev:event="xforms-valid">
</xforms:action>
</xforms:input>

<xforms:group/>

<xforms:output ref="/data/valid/string1" id="label1">
<xforms:label id="label11">Name : </xforms:label>
</xforms:output>

<xforms:group/>

<xhtml:input type="button" value="test" onclick="affiche();"/>
</xhtml:body>
</xhtml:html>

That's all :)

Sep 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.