Didn't works either ...

Here is the solution I had found. Instead use the toggle() function,
which cause this issue, I use the click() function with an if()
statement.

        function myToggle(checkboxElem, showHideElem){
            var showHide = $(showHideElem);
            var checkbox = $(checkboxElem);
            checkbox.click( function() {
              if (checkbox.is(":checked")) {
                showHide.show('slow');
              } else {
                showHide.hide('slow');
              }
            });
        }

This works fine now.

Thanks for your help Wizzud.

Cheers,
Damien


On Nov 5, 8:09 pm, Wizzud <[EMAIL PROTECTED]> wrote:
> Yeah, it was a bit thoughtless of me to suggest it (tired!).
> Try this instead...(untested)...
>
> function myToggle(toggleElem, showHideElem){
>   var showHide = $(showHideElem);
>   $(toggleElem).toggle(
>     function(){ showHide.show('slow'); toggleElem.checked = !
> toggleElem.checked; },
>     function(){ showHide.hide('slow'); toggleElem.checked = !
> toggleElem.checked; } );
>
> }
>
> On Nov 5, 2:34 pm, Snook <[EMAIL PROTECTED]> wrote:
>
> > I also have tried, like you suggested, to use the .each() function.
>
> > function myToggle(toggleElem, showHideElem){
> >         var showHide = $(showHideElem);
> >         $(toggleElem).toggle(
> >                 function(){ showHide.show('slow');},
> >                 function(){     showHide.hide('slow');}
> >         ).each(function() {
> >           if ($(toggleElem).is(":checked")) {
> >             $(this).attr("checked", "");
> >           } else {
> >             $(this).attr("checked", "checked");
> >           }
> >         });
>
> > }
>
> > But this is not successful !
>
> > On Nov 3, 1:15 am, Wizzud <[EMAIL PROTECTED]> wrote:
>
> > > function myToggle(toggleElem, showHideElem){
> > >   var showHide = $(showHideElem);
> > >   $(toggleElem).toggle(
> > >     function(){ showHide.show('slow'); },
> > >     function(){ showHide.hide('slow'); } )
> > >     .each(function(){ this.checked = !this.checked; });
>
> > > }
>
> > > On Nov 2, 12:21 pm, Snook <[EMAIL PROTECTED]> wrote:
>
> > > > > Calling toggle() runs event.preventDefault.
> > > > > Whatever you want the click to do, you need to code it yourself.
>
> > > > Ok, thanks.
> > > > I have tried different implementation of preventDefault, regarding
> > > > what I have found in this group. And probably I'm completely wrong
> > > > because no one works for me.
>
> > > > Here is what I have tried:
>
> > > > function myToggleShow(toggleElem, showHideElem){
> > > >           var showHide = $(showHideElem);
> > > >           $(toggleElem).toggle(
> > > >             function(e){
> > > >                 e.eventDefault();
> > > >                 showHide.show('slow');
> > > >             },
> > > >             function(){ showHide.hide('slow'); }
>
> > > >           );
>
> > > > }
>
> > > > myToggleShow('#regime_lstd_c', '#regime_lstd');
>
> > > > Did I need an other plugin or library ?

Reply via email to