This (untested) is how I envision the code for that: $.fn.dragCheck = function(){ //this == the current jQuery element return this.each(function(){
//this == current element in the loop (table etc) $(this).bind('mousedown', function(e){ //don't do anything if you didn't click a checkbox if ( !$(e.target).is(':checkbox') ) return true; //get the clicked checkbox state isChecked = e.target.checked; //apply it to all other checkboxes on mouseover $boxes.bind('mouseover.dc', function(){ this.checked = isChecked; }); }).bind('mouseup', function(e){ //cancel the mouseover action $boxes.unbind('mouseover.dc'); }); }; $('#table1').dragCheck(); cheers, - ricardo On 9 abr, 17:15, Lwangaman <donjohn.f...@gmail.com> wrote: > Ok I resolved the "cannot assign to a function result" problem by > putting the value assignment into a "function(){}": > > 48 $("td.mychkbox").each( > 49 function(){ > 50 $(this).bind( > 51 "mouseover", > 52 function(){ > 53 if (gCheckedValue != null){ > 54 var eccomi = this; > 55 var eccoti = $(eccomi).find("input:checkbox"); > 56* function(){$(eccoti).attr("checked") = gCheckedValue;} > 57 } > 58 }); > 59 }); > > Now I don't get any errors, but the event assignments don't seem to be > working together correctly... > Basically what's supposed to happen is this: > 1 - "onclick" event of the checkboxes is canceled since the clicking > and dragging is being assigned to the table cells that contain them > 2 - the table cells themselves don't actually have on "onclick" event, > because the value is given to the checkboxes with the "onmousedown" > and especially the "onmouseover" event. > 3 - "onmousedown" gives the variable "gCheckedValue" a value, either > of "true" or of "false" (depending on the actual state of the > checkbox, so if it is unchecked it will get checked and vice-versa), > and "onmouseup" empties "gCheckedValue" of any value. So as long as > the mouse is down, "gCheckedValue" has a value to give to any of the > checkboxes with the "onmouseover" event, but as soon as the mouse > button is released it no longer has a value so the "onmouseover" event > will no longer effect any of the checkboxes until the mousebutton is > pressed again. > > So the value of "gCheckedValue" is set in the "mousedown" event, and > is transmitted in the "mouseover" event. > > And yet the code doesn't seem to be working correctly. The current > value of the cell is detected correctly (I've gotten it through an > alert), it's contrary is correctly set in "gCheckedValue" (I've gotten > that through an alert too), but the new value is not being set in the > checkbox... In fact click sets no value, click and hold sets no value, > click and drag (mouseover the other checkboxes / cells) set no > value... > > On 9 Apr, 14:23, Lwangaman <donjohn.f...@gmail.com> wrote: > > > I thought I'd undertake the endeavour of translating into jquery the > > neat little "click-n-drag checkboxes" functionality of cross- > > browser.com's X-library. This functionality allows for multiple > > checkbox selection or de-selection by simply clicking on one of them > > and then dragging the mouse over the others. > > > I began mentioning this in another post, but I figured that perhaps a > > new post with the right title would be better. Rather than re-post all > > the code though, here's a reference to the message where the full code > > of both the X-library functions and my attempted translation of them > > is posted: > > >http://groups.google.com/group/jquery-en/msg/0f38d747d97cf701 > > > I doesn't quite seem to work though, none of my checkboxes are getting > > selected either on click or on drag. Any javascript - jquery experts > > have any ideas on what needs to be perfected? > > > When I run it in Internet Explorer, the debugger gives me this > > message: > > "Cannnot assign to a function result" > > > and it refers to line 56, which should be the one that sets the > > selection: > > > 48 $("td.mychkbox").each( > > 49 function(){ > > 50 $(this).bind( > > 51 "mouseover", > > 52 function(){ > > 53 if (gCheckedValue != null){ > > 54 var eccomi = this; > > 55 var eccoti = $(eccomi).find("input:checkbox"); > > 56* $(eccoti).attr("checked") = gCheckedValue; > > 57 } > > 58 }); > > 59 });