Link to home
Create AccountLog in
Avatar of Nika Gudge
Nika GudgeFlag for United States of America

asked on

Link not working

I have the below code in the xsl file
Link to config does not work.

    <script LANGUAGE="JavaScript" type="text/javascript" nonce="{$vNonce}">
          function ChangeMenu(servlet, type) {
          document.MainForm.disp.value     = 1;
          document.MainForm.abaction.value = type;
          document.MainForm.action         = servlet;
          document.MainForm.submit();
      }
    </script>
    <script type="text/javascript" nonce="{$vNonce}">
          document.addEventListener('DOMContentReady', function () {
              document.getElementById("config").addEventListener('click', ChangeMenu('Admin','config'), false);
            });
    </script>
<a class="clsMenuNormal" href="#" id="config">Config</a>
Avatar of Shalu M
Shalu M
Flag of United States of America image

Try this -

 <script language="JavaScript" type="text/javascript"  nonce="{$vNonce}">
        function ChangeMenu(servlet, type) {
            alert('success');
            //document.MainForm.disp.value = 1;
            //document.MainForm.abaction.value = type;
            //document.MainForm.action = servlet;
            //document.MainForm.submit();
        }
 
       function init() {
            document.getElementById("config").addEventListener("click", ChangeMenu('Admin', 'config'));
        }

        window.addEventListener('load', init);

</script>
Avatar of Nika Gudge

ASKER

i do get a success alert box when the page loads. But after loading when the link is clicked the link does not work.
# is added to the url and nothing happens
http://localhost:8080/abc/servlet/Admin#
Avatar of Leonidas Dosas
What is the Mainform property? I think you don't declare right the MainForm property.If you post the HTML code of the form I think that we can be more efficient to our answers.
MainForm is the form name. It has multiple links defined using xsl if else.
MainForm calls the menu.xsl <xsl:call-template name="menu"/> template which has the javascript for function ChangeMenu

    <script type="text/javascript" nonce="{$vNonce}" >
          document.addEventListener('DOMContentReady', function () {
              window.document.getElementById("config").addEventListener('click', ChangeMenu('Admin','config'));
            });
    </script>
    <script type="text/javascript" nonce="{$vNonce}" >
          document.addEventListener('DOMContentReady', function () {
              document.getElementById('receipt').addEventListener('click', ChangeMenu('Admin','receipt'));
            });
    </script>

    <body bgcolor="#ffffff" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" rightmargin="0" bottommargin="0">
<xsl:call-template name="menu"/>
      </body></html>
</xsl:template>
<xsl:template name="main">
    <form name="MainForm" action="{$servlet_loc}Admin" method="post">
    <input type="hidden" name="abaction" value=""/>
    <table align="center" width="500">
    <tr><td class="pageTitleFont" valign="middle">Main Menu</td></tr>
    <tr height="5"><td></td></tr>
    <tr><td align="center">
        <table class="tablebox3" align="center" width="{$vWidth}" cellpadding="1" cellspacing="0" border="0">
            <tr>
                <td colspan="6" class="reportheader">Settings</td>
            </tr>
            <tr>
                <td align="center" >
                    <table>
                        <tr align="center">
                                  <td><a href="#" id="config"><img src="{$page_loc}images/details.gif" align="absmiddle" height="75" width="75" border="0"/>Config</a></td>
                        </tr>
                        <tr align="center">
                            <td class="clsMenuNormal"><a class="clsMenuNormal" href="#" id="config">Config</a></td>
                        </tr>
                    </table>
                <td align="center">
                    <xsl:if test="$vRole!='4'">
                    <table>
                        <tr align="center">
                            <td><a href="#" id="emailreceipt"><img src="{$page_loc}images/receipt.gif" align="absmiddle" height="75" width="75" border="0"/>Receipt</a></td>
                        </tr>
                        <tr align="center">
                            <td class="clsMenuNormal"><a class="clsMenuNormal" href="#" id="receipt">Receipt</a></td>
                        </tr>
                    </table>
                    </xsl:if>
                </td>
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
solution worked