6 Replies Latest reply on Jun 9, 2008 1:22 PM by I B

    jquery

    I B Newbie

      I have a jquery problem, i donèt know hot to use it...

      here is my small code,


      alert('zzz')
      $(document).ready(function()
      { alert('yyy')
      $("#selDesAllCheckBox").click(function()
      { alert('xxx')
      var checked_status = this.checked;
      $("input[@name=paradigm]").each(function()
      {
      this.checked = checked_status;
      });
      });
      });

      <h:selectBooleanCheckbox id="selDesAllCheckBox"/>





      this is just 3 checkboxes and one is selecting the others if selected!
      but the jquery doesnèt seem to be called up at all ''alert('yyy')''! Anybody knows what i'm doing wrong?

        • 1. Re: jquery
          I B Newbie

          Soory the code didn't show up..

           <script type="text/javascript">
           alert('zzz')
           $(document).ready(function()
           { alert('yyy')
           $("#selDesAllCheckBox").click(function()
           { alert('xxx')
           var checked_status = this.checked;
           $("input[@name=paradigm]").each(function()
           {
           this.checked = checked_status;
           });
           });
           });
           </script>
           <h:selectBooleanCheckbox id="selDesAllCheckBox"/>
           <input type="checkbox" name="paradigm" value="Imperative"/>
           <input type="checkbox" name="paradigm" value="Object-Oriented"/>
          


          • 2. Re: jquery
            Sergey Smirnov Master

            RichFaces is shipped with JQuery. Do you use it or add your own copy to the project?

            • 3. Re: jquery
              I B Newbie

              I use the standard one that comes with richfaces...
              i just want to do the function with rich:query...
              and didn't have any success at all!

              i also tried to do it by loading


              <a4j:loadScript src="resource:///org/richfaces/renderkit/html/scripts/jquery/jquery.js"/>


              but still didn't work any idea what i'm doing wrong?

              • 4. Re: jquery
                Sergey Smirnov Master

                First of all, you have to use jQuery() instead of $(). It is mentioned right in the second paragraph of jQuery demo: http://livedemo.exadel.com/richfaces-demo/richfaces/jQuery.jsf

                Also, do not forget that JSF adds prefix to the each id of the form element. So, even you have jQuery("#selDesAllCheckBox"), it might not be working because the id of the checkbox might not be a "selDesAllCheckBox", but something like "myform:selDesAllCheckBox". So, the selector should be jQuery("#myform:\\selDesAllCheckBox")

                P.S. Why not using rich:jQuery in your concrete case? It will some both problem you have implicitly.

                • 5. Re: jquery
                  I B Newbie

                  thanks for the reply Sergey...

                  yes i try to use rich:jquery but im unable to reproduce the function with rich:jquery



                  <script type="text/javascript">
                   alert('zzz')
                   $(document).ready(function()
                   { alert('yyy')
                   $("#selDesAllCheckBox").click(function()
                   { alert('xxx')
                   var checked_status = this.checked;
                   $("input[@name=paradigm]").each(function()
                   {
                   this.checked = checked_status;
                   });
                   });
                   });
                   </script>
                   <h:selectBooleanCheckbox id="selDesAllCheckBox"/>
                   <input type="checkbox" name="paradigm" value="Imperative"/>
                   <input type="checkbox" name="paradigm" value="Object-Oriented"/>


                  • 6. Re: jquery
                    I B Newbie

                    oki got it finally

                    <rich:jQuery timing="onload" selector="#selDesAllCheckBox" query="click( function(){ var checked_status = this.checked; jQuery('input[@name=paradigm]').each(function(){this.checked = checked_status;}); } );"/>