We help IT Professionals succeed at work.

Link not working

Newton21205
Newton21205 asked
on
165 Views
Last Modified: 2017-04-02
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>
Comment
Watch Question

Commented:
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>

Author

Commented:
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#
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.

Author

Commented:
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>
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
solution worked

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions