How can we call a javascript function present in another jsp file.?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaaash
    New Member
    • May 2010
    • 10

    How can we call a javascript function present in another jsp file.?

    <script type="text.java script" src="/NewPrototype/jsp/caldata.jsp"></script>

    I am trying to call javascript function named( show() ) from index.jsp which is present in caldata.jsp but it is not calling that function.

    How we can call a function which is present in script of another jsp page?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    maybe this works
    Code:
    <script type="text/javascript" src="/NewPrototype/jsp/caldata.jsp"></script>
    otherwise consult the error console.

    Comment

    • aaaash
      New Member
      • May 2010
      • 10

      #3
      Originally posted by Dormilich
      maybe this works
      Code:
      <script type="text/javascript" src="/NewPrototype/jsp/caldata.jsp"></script>
      otherwise consult the error console.
      Thanks for your reply..
      I checked in error console it says show() func is not defined.Now what i need to do?
      Thanks in advance

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        check if you can manually call the JavaScript file in the browser (via address bar).

        Comment

        • aaaash
          New Member
          • May 2010
          • 10

          #5
          As you suggested i manually called that jsp page where javascript is present it is displaying the content.
          To get better idea of what I am doing, I am posting code which is in complete..
          in index.jsp

          Code:
          <A HREF="javascript:void(null);" onclick="showFilterChoices('Language');">
          <script type="text/javascript" src="/NewPrototype/jsp/caldata.jsp"></script>
          in caldata.jsp
          i have defined showFilterChoic es function like this

          Code:
          <script type="text/javascript">
          function showFilterChoices( whichFilter )
          {
          }
             </script>
          What may be the error here?
          Last edited by Dormilich; May 28 '10, 09:58 AM. Reason: Please use [code] tags when posting code

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            external JavaScript files do not use <script> tags (that is for HTML pages to denote a JS section).

            your JSP file should send a javascript header.

            I suppose your function is not empty in reality.

            Comment

            • aaaash
              New Member
              • May 2010
              • 10

              #7
              Originally posted by Dormilich
              external JavaScript files do not use <script> tags (that is for HTML pages to denote a JS section).

              your JSP file should send a javascript header.

              I suppose your function is not empty in reality.
              Yes my function is not empty..

              Can u plz tell how can jsp file send a js header..?? Give Ex

              In caldata.jsp i am writing some function in <body> of it.So i wrote js function within <script>

              Thanks you in advance..

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Can u plz tell how can jsp file send a js header..?? Give Ex
                sorry, I’m not a Java guy. I could tell you how to do it in PHP though …

                In caldata.jsp i am writing some function in <body> of it.So i wrote js function within <script>
                that means, you include an entire HTML page via <script>? no wonder it doesn’t work …

                an external JavaScript file must only contain pure JavaScript code. that is, no tags around it.

                Comment

                • aaaash
                  New Member
                  • May 2010
                  • 10

                  #9
                  Originally posted by Dormilich
                  sorry, I’m not a Java guy. I could tell you how to do it in PHP though …



                  that means, you include an entire HTML page via <script>? no wonder it doesn’t work …

                  an external JavaScript file must only contain pure JavaScript code. that is, no tags around it.
                  OK. Thanks for your suggestion.

                  Comment

                  Working...