[jQuery] Re: Get label text
I wrote alert(levels) to check and I get: [object Object] Does anyone knows how to get the values and join in CSV format? Thank You, Miguel On Oct 24, 1:47 am, shapper [EMAIL PROTECTED] wrote: yes, I have: var levels = []; levels = $('input:checked + label').map(function() { return $(this).text(); }); ... .append(levels.join(',')) Still having the same error ... On Oct 24, 1:04 am, William [EMAIL PROTECTED] wrote: Perhaps use .append(labels.join(',')) Note that the snippet from Klaus uses var *labels*, so trying to use the Array.join method of *levels* (probably undefined) will likely not work ;) On Oct 23, 2:58 pm, shapper [EMAIL PROTECTED] wrote: But I can join the labels can't I? I tried: .append(levels.join(', ')) to added it to an element and I get the error in Firebug: levels.join is not a function Am I doing something wrong? Thanks, Miguel On Oct 23, 9:57 pm, Klaus Hartl [EMAIL PROTECTED] wrote: You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel
[jQuery] Re: Get label text
Ah, I forgot a little thing (documentation was a bit misleading on that). Try this: var levels = $('input:checked + label').map(function() { return $(this).text(); }).get(); For csv do: levels.join(','); And that's more or less the same as in the documentation ;-) http://docs.jquery.com/Traversing/map#callback --Klaus On 24 Okt., 14:03, shapper [EMAIL PROTECTED] wrote: I wrote alert(levels) to check and I get: [object Object] Does anyone knows how to get the values and join in CSV format? Thank You, Miguel On Oct 24, 1:47 am, shapper [EMAIL PROTECTED] wrote: yes, I have: var levels = []; levels = $('input:checked + label').map(function() { return $(this).text(); }); ... .append(levels.join(',')) Still having the same error ... On Oct 24, 1:04 am, William [EMAIL PROTECTED] wrote: Perhaps use .append(labels.join(',')) Note that the snippet from Klaus uses var *labels*, so trying to use the Array.join method of *levels* (probably undefined) will likely not work ;) On Oct 23, 2:58 pm, shapper [EMAIL PROTECTED] wrote: But I can join the labels can't I? I tried: .append(levels.join(', ')) to added it to an element and I get the error in Firebug: levels.join is not a function Am I doing something wrong? Thanks, Miguel On Oct 23, 9:57 pm, Klaus Hartl [EMAIL PROTECTED] wrote: You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel
[jQuery] Re: Get label text
You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel
[jQuery] Re: Get label text
But I can join the labels can't I? I tried: .append(levels.join(', ')) to added it to an element and I get the error in Firebug: levels.join is not a function Am I doing something wrong? Thanks, Miguel On Oct 23, 9:57 pm, Klaus Hartl [EMAIL PROTECTED] wrote: You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel
[jQuery] Re: Get label text
Perhaps use .append(labels.join(',')) Note that the snippet from Klaus uses var *labels*, so trying to use the Array.join method of *levels* (probably undefined) will likely not work ;) On Oct 23, 2:58 pm, shapper [EMAIL PROTECTED] wrote: But I can join the labels can't I? I tried: .append(levels.join(', ')) to added it to an element and I get the error in Firebug: levels.join is not a function Am I doing something wrong? Thanks, Miguel On Oct 23, 9:57 pm, Klaus Hartl [EMAIL PROTECTED] wrote: You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel
[jQuery] Re: Get label text
yes, I have: var levels = []; levels = $('input:checked + label').map(function() { return $(this).text(); }); ... .append(levels.join(',')) Still having the same error ... On Oct 24, 1:04 am, William [EMAIL PROTECTED] wrote: Perhaps use .append(labels.join(',')) Note that the snippet from Klaus uses var *labels*, so trying to use the Array.join method of *levels* (probably undefined) will likely not work ;) On Oct 23, 2:58 pm, shapper [EMAIL PROTECTED] wrote: But I can join the labels can't I? I tried: .append(levels.join(', ')) to added it to an element and I get the error in Firebug: levels.join is not a function Am I doing something wrong? Thanks, Miguel On Oct 23, 9:57 pm, Klaus Hartl [EMAIL PROTECTED] wrote: You could try this (untested): var labels = $('input:checked + label').map(function() { return $(this).text(); }); That should give you an array with the label's text. --Klaus On 23 Okt., 22:47, shapper [EMAIL PROTECTED] wrote: Hello, This might be a tricky one ... I have been looking into JQuery docs but I can't figure how to make this. I have the following: input type=checkbox name=Roles id=Admin value=Admin / label for=AdminAdministrator/label input type=checkbox name=Roles id=Coll value=Admin / label for=CollCollaborator/label How can I get, NOT the values, of all checked boxes BUT the label inner text of all checked boxes? Example: If Coll checkbox is checked I would get: Collaborator If both checkboxes are checked I would get: Collaborator, Administrator Could someone, please, help me? Thank You, Miguel