473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
5 2547


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

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


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
ok thank you Martin for your help

Aug 25 '06 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: aimee | last post by:
Hi. Is there a way to capture the events fired in a PrintDialog? I would like to capture when the user presses "Print" so I can do some cleanup. The asp.net (IE6) application I'm working on has 6...
2
by: jva02 | last post by:
Hi, I'm confused why I can capture an event fired by an ActiveX object when it's loaded via an <object> tag, but not when loaded using "new ActiveXObject". Here's a basic example: vb ActiveX...
15
by: Jake Barnes | last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a little toy that I can do tests with. You can see it here: http://www.publicdomainsoftware.org/ajaxExperiment.htm I've got...
5
by: vjsv2007 | last post by:
Can you help to make one alert with all details? <script type="text/javascript"> <!-- function validate_form ( ) { valid = true;
2
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. ...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
1
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming...
5
by: vasilis | last post by:
I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below). This function passes 2 arguments, i.e., 'str' which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.