8 Replies Latest reply on Jun 1, 2009 7:43 AM by nbelaevski

    Including JS file


      Hi all,

      I just want to make my validations on teh client side using java script so i thought of including my script file like this

      <script src="JS/NominationScripts.js" type="text/javascript"></script>
      


      i had included the above in my head part
      and my js file is there in the path as specified

      when i include that part im getting error where the javascript function need to be called saying object expected.

      im calling the function like this
      <h:inputText value="#{registerBean.userId}" id="userIdit"
       onkeyup="tester()">
      


      and my js file is not having any errors

      i even tried with empty js file without any contents. still the same problem. when page is loading it is showing me a script error.

      pls help




        • 1. Re: Including JS file
          ilya_shaikovsky

          include the JS via loadScript in the next way:

          <a4j:loadScript src="/JS/NominationScripts.js">
          


          It will generate the full path including context path. Currently you have problems with relative path.

          • 2. Re: Including JS file

            i i ncluded teh same in the form and got this on client side

            <script src="/NominationWeb/JS/NominationScripts.js" type="text/javascript">
            


            still teh same problem exists.

            this is in my js file

            
            function tester(){
             alert("Hi..");
            }
            


            nothing more than this

            pls help

            • 3. Re: Including JS file
              ilya_shaikovsky

               

              "ilya_shaikovsky" wrote:
              include the JS via loadScript in the next way:
              <a4j:loadScript src="/JS/NominationScripts.js">
              


              <b>It will generate the full path including context path.</b> Currently you have problems with relative path.


              if you want to use src it should be related according to context path like
              <script src="/JS/NominationScripts.js" type="text/javascript">



              • 4. Re: Including JS file

                including the thing you said had solved me the page load script problem
                but i tried calling method in my js like this

                <h:inputText value="#{registerBean.userId}" id="userIdit"
                 onkeyup="tester()">
                


                it is throwing me with javascript erro again saying object expeted

                thanks in advance

                • 5. Re: Including JS file
                  ilya_shaikovsky

                  and this is a problem in your JS for sure. works fine for us.. we using the same approach at demosite. You could visit and check. (component control zoom sample.)

                  • 6. Re: Including JS file

                    i tried calling some java script in build functions in teh placve of my function
                    they were working only the included scripts functions were not working.

                    i had cross cheked twice in my js file for any issues

                    i cant find any ...

                    here is my js file contents

                    function testme(){
                     alert("Hi...!!");
                    }
                    


                    nothing more than this..



                    • 7. Re: Including JS file

                      if i paste the contents like this in my page it working fine

                      <script type="text/javascript">
                      function testme(){
                       alert("Hi...!!");
                      }
                      </script>
                      


                      only its not picking up from JS file

                      • 8. Re: Including JS file
                        nbelaevski

                        Check if there are any errors loading scripts with Firebug tool (use "Net" tab).