Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to capture and alert the value of an xhtml node using JS

Reply
Thread Tools

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

 
 
sniper
Guest
Posts: n/a
 
      08-25-2006
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"
xmlnshtml="http://www.w3.org/1999/xhtml"
xmlnsforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnss="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/>

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

thanks for any help

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-25-2006


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/
 
Reply With Quote
 
 
 
 
sniper
Guest
Posts: n/a
 
      08-25-2006

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;

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      08-25-2006


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/
 
Reply With Quote
 
sniper
Guest
Posts: n/a
 
      08-25-2006
ok thank you Martin for your help

 
Reply With Quote
 
sniper
Guest
Posts: n/a
 
      09-07-2006
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"
xmlnshtml="http://www.w3.org/1999/xhtml"
xmlnsforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnss="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/>

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

<xforms:group/>

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

That's all

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
<need help>How to print the preceding node value based on descendant node in XSLT? njsimha XML 0 09-16-2008 12:33 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Select Node Using position or value of another node. Eddy C XML 6 10-17-2005 11:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57