Re: [Xsltforms-support] Setting node value in javascript
Brought to you by:
alain-couthures
From: Mark S. <m_s...@ma...> - 2012-07-15 07:57:51
|
Hi, Here is a simple form that I hope should set the text value of an XML node using a Javascript function. If this is happening it is not reflected in the ui. Am I doing something wrong? My scripting skills are not what they used to be, so I could easily have made a basic mistake in the js function. Best wishes Mark <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="../xsltforms/xsltforms.xsl" type="text/xsl"?> <?xsltforms-options debug="no"?> <?css-conversion no?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events"> <head> <title>Discover your Whithorn</title> <script type='text/javascript'> function onFeatureSelect(evt) { var modelElem = document.getElementById("theModel"); var instDoc = modelElem.getInstanceDocument("variables"); var xmlSite = instDoc.getElementsByTagName("currSite")[0]; xmlSite.childNodes[0].nodeValue = evt; alert(xmlSite.childNodes[0].nodeValue); modelElem.rebuild(); modelElem.recalculate(); modelElem.revalidate(); modelElem.refresh(); } </script> <xf:model id="theModel"> <xf:instance id="sites" xmlns=""> <sites> <featureMember> <site> <name>Cairn Buy</name> </site> </featureMember> <featureMember> <site> <name>'Hole Stone'</name> </site> </featureMember> </sites> </xf:instance> <xf:instance id="variables" xmlns=""> <doc> <currSite>Cairn Buy</currSite> </doc> </xf:instance> </xf:model> </head> <body> <h2>Sites</h2> <div> <p>Value of instance('variables')/currSite is: <strong><xf:output value="instance('variables')/currSite"/></strong></p> <xf:select1 ref="instance('variables')/currSite"> <xf:itemset nodeset="instance('sites')/featureMember/site"> <xf:label ref="name"/> <xf:value ref="name"/> </xf:itemset> </xf:select1> <p onclick="onFeatureSelect('Hole Stone')">Set value of instance('variables')/currSite to Hole Stone</p> <p onclick="onFeatureSelect('Cairn Buy')">Set value of instance('variables')/currSite to Cairn Buy</p> </div> </body> </html> |