Re: [jQuery] Checkbox: Selecting all Previous

2006-11-29 Thread Alex Cook
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Glen Lipka
Sent: Wednesday, November 29, 2006 9:52 AM
To: jQuery Discussion.
Subject: Re: [jQuery] Checkbox: Selecting all Previous

QUESTION OR FEATURE SUGGESTION
arrayPos() would return the index of the array.
 
So if I had 4 links with a class of "foo" and I clicked the third one,
$arrayPos(".foo", this) would return 3 (or 2 if it started at zero).
Maybe I should put this in a seperate message?
 
Glen

--

Actually I was looking over the suggestion I made earlier, and noticed that I 
didn't need to figure out the array position like I had.  Here's the modified 
code.

$("[EMAIL PROTECTED]").each(function (i) {
 $(this).bind("click",function () {
  $(this).siblings("[EMAIL PROTECTED]").lt(i).each(function () {
   $(this).attr({checked: 'true'});
  }
 )
}

>From the API docs: 'Additionally, the (each) function, when executed, is 
>passed a single argument representing the position of the element in the 
>matched set.'

That's all we want, so by including the 'i' we remove the need for the id or 
any other attribute to discern where the object is in the array.  Again, tested 
in FF2/Win only.

I can see where arrayPos would be a good function tho, just not necessary in 
this case.

-ALEX

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Checkbox: Selecting all Previous

2006-11-29 Thread Glen Lipka

I changed some of it and stopped using the checkboxes, but this would work
with the checks too.  I need the ID attribute for something else, soI used
the REL attribute as proscribed.

$(".checkbox").click( function()
{
currentOption = parseInt($(this).attr("rel")) + 1;

$("#options div.checkbox").removeClass("checked");
$("#options div.checkbox").lt(currentOption).addClass("checked");

} );

I wish there was a way of getting the position in an array.

QUESTION OR FEATURE SUGGESTION
arrayPos() would return the index of the array.

So if I had 4 links with a class of "foo" and I clicked the third one,
$arrayPos(".foo", this) would return 3 (or 2 if it started at zero).
Maybe I should put this in a seperate message?

Glen
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Checkbox: Selecting all Previous

2006-11-27 Thread dave.methvin


Glen Lipka wrote:
> 
> I have 4 checkboxes vertical
> 
> box 1type="checkbox">box 1 and 2type="checkbox">box 1 and 2 and 3  type="checkbox">box 1 and 2 and 3 and 4
> 
> When I click one, I want to check the boxes of all the ones previous to it
> (including it).  And uncheck all the boxes after it.
> 
I thought about an approach that checked all the boxes then cleared the ones
following the checked one by using selectors and DOM navigation, but I think
it's much simpler to do an each() instead. 

$(document).ready(function(){
  $("#myform checkbox").bind("click", function(){
var mybox = this;
var tick = true;
$("myform checkbox").each(function(){
  this.checked = tick;
  if ( this == mybox )
tick = false;
});
  });
});
-- 
View this message in context: 
http://www.nabble.com/Checkbox%3A-Selecting-all-Previous-tf2715371.html#a7572127
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Checkbox: Selecting all Previous

2006-11-27 Thread Alex Cook
I couldn't figure out to do it unless I added some form of ID to each
input field.  I'm not sure how one can get the place of an element
within a jQuery object, so this is how I approached your problem.

 

Tested in Win/FF2

 



box 1   

box 1 and 2   

box 1 and 2 and
3 

box 1 and 2 and 3 and
4



 



 

$(document).ready(

function () {

$("[EMAIL PROTECTED]").each(

function () {

$(this).bind(

"click",

function ()
{

 
$(this).siblings("[EMAIL PROTECTED]").lt($(this).id()-1).each(

 
function () {

 
$(this).attr(

 
{

 
checked: 'true'

 
}

 
);

 
}

 
)

}

)

}

)

}

);

 



 

The code can be cleaned up a bit, but I like making it verbose while
trying to figure things out so that's what you get.

 

If someone knows how to snag the place of an element within a jQuery
collection so that number can be passed to the lt() function I'd love to
hear it.

 

-ALEX

 



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Glen Lipka
Sent: Monday, November 27, 2006 4:27 PM
To: jQuery Discussion.
Subject: [jQuery] Checkbox: Selecting all Previous

 

This might be a newbie question, but I am having trouble with it.

 

I have 4 checkboxes vertical

 

box 1   

box 1 and 2   

box 1 and 2 and 3 

box 1 and 2 and 3 and 4

 

When I click one, I want to check the boxes of all the ones previous to
it (including it).  And uncheck all the boxes after it.

 

How would I structure the statement in jQuery to select?  I am trying to
avoid the FOR loop.

 

This gives me the last one.

var lastOne = $("#myForm [EMAIL PROTECTED]:checked:last");

 

Not sure how to use this.  I tried prev() but that didnt seem to work.

 

Thanks for the help,


Glen

 

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/