Web Analytics Made Easy -
StatCounter Assigning multiple functions to a button - CodingForum

Announcement

Collapse
No announcement yet.

Assigning multiple functions to a button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assigning multiple functions to a button

    Hi,

    I am creating a tool to merge xml files using xslt using Javascript/HTML.

    Basically the user browses (browse button) to where there xml files are, then browses to where their xslt file (to perform an operation) is. Then they click an "apply" button and the result is output in a frame below.

    My problem:

    I have the tool working fine when I only have one input xml file (which is no good in a merge tool!!) but when I modify the code and add another xml field, the apply button will not work for two fields!

    I think I haven't assigned the functions correctly to the xml fields/apply button. Heres some of the code I suspect is wrong, but im not sure where??

    <table width="800">
    <tr>
    <td width="370">
    XML File 1
    <input type="file" size=15 id="xmlField1">
    <input type="button" value="XML Src" onClick="ApplyStyleSheet(xmlField1.value, 'defaultss.xml');" id=xmlsrc name=xmlsrc>
    XML File 2
    <input type="file" size=15 id="xmlField2">
    <input type="button" value="XML Src" onClick="ApplyStyleSheet(xmlField2.value, 'defaultss.xml');" id=xmlsrc name=xmlsrc>
    </td><td> </td>
    <td width="370">
    XSL File
    <input type="file" size=15 id="xslField">

    <input type="button" value="XSL Src" onClick="ApplyStyleSheet(xslField.value, 'defaultss.xml');" id=xslsrc name=xslsrc>
    </td></tr>
    <tr><td> </td>
    <td width="80">
    <input type="button" value="Apply" onClick="ApplyStyleSheet(xmlField1.value && xmlField2.value, xslField.value);">
    </td><td> </td>
    </tr>
    </table>

    Any suggestions/advice/feedback would be greatly appreciated.

    Many Thanks
    Ciaran

    PS Any more questions/need to see the file please email me.

  • #2
    ApplyStyleSheet(xmlField1.value && xmlField2.value, xslField.value);

    That's where the error is. You have to also post the content of the ApplyStyleSheet function to help us fix your problem.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      More code for function problem

      Hi,

      Thanks for your response. Much appreciated... Heres all the code (not too much) maybe this might help make things a bit more clear.

      <html>
      <head>
      <XML id=xmlisl></XML>
      <XML id=xslisl></XML>

      <script language="javascript">
      function LoadFile(xmldoc, url)
      {
      xmldoc.async = false;
      var errortxt = "";
      try
      {
      xmldoc.load(url);
      errortxt = xmldoc.parseError.reason;
      }
      catch(e)
      {
      errortxt = e.description;
      }
      if (errortxt)
      {
      alert("While Loading: "+url+"\n"+ errortxt);
      return null;
      }
      return xmldoc;
      }

      function ApplyStyleSheet(xml, xsl)
      {
      var xmlUrl = xml;
      var xslUrl = xsl;
      var xmldoc = xmlisl.XMLDocument;
      var xsldoc = xslisl.XMLDocument;
      if (LoadFile(xmldoc, xmlUrl) &&
      LoadFile(xsldoc, xslUrl))
      {
      try
      {
      var htmltxt = xmldoc.transformNode(xsldoc);
      var htmldoc = window.parent.frames(1).document;
      htmldoc.open();
      htmldoc.write(htmltxt);
      htmldoc.close();
      }
      catch(e)
      {
      alert("Error during TransformNode()\n" + e.description);
      }
      }
      }
      </script>
      </head>

      <body>

      <table width="800">
      <tr>
      <td width="370">
      XML File 1
      <input type="file" size=15 id="xmlField1">
      <input type="button" value="XML Src" onClick="ApplyStyleSheet(xmlField1.value, 'defaultss.xml');" id=xmlsrc name=xmlsrc>
      XML File 2
      <input type="file" size=15 id="xmlField2">
      <input type="button" value="XML Src" onClick="ApplyStyleSheet(xmlField2.value, 'defaultss.xml');" id=xmlsrc name=xmlsrc>
      </td><td> </td>
      <td width="370">
      XSL File
      <input type="file" size=15 id="xslField">

      <input type="button" value="XSL Src" onClick="ApplyStyleSheet(xslField.value, 'defaultss.xml');" id=xslsrc name=xslsrc>
      </td></tr>
      <tr><td> </td>
      <td width="80">
      <input type="button" value="Apply" onClick="ApplyStyleSheet(xmlField1.value && xmlField2.value, xslField.value);">
      </td><td> </td>
      </tr>
      </table>

      </body>
      </html>

      Thanks in advance
      Ciaran

      Comment


      • #4
        The question here is, do you really can merge two XML files into one and then apply styles into it? I don't see any "xml-merging" code in the ApplyStyleSheet function. You also need to modify the function not only the call to it, like you were doing.
        Glenn
        vBulletin Mods That Rock!

        Comment

        Working...
        X