• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Need Help with Jquery.each

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to find all checked rows and then grab all the values from each cell for each row.

So what I did was this

var checked = $('.chk_plannerCheckBoxes :checked').parent('span').parent('td').parent('tr');

So this found me the all the checked rows what I wanted.

Next I want to go through each row one by one and get the row and then all the cells from that row through ajax to the server for processing.

jQuery.each(checked, function(i, value)
{
// this grabs all the cells from the row.
var cells = $(value).children('td');

// I tried to then grab the value say from cell 1 but I always just get and error. I also tried .html() but got the same thing. I also tried just to send cells[1] but it just sends the objects name.
var test = cells[1].val();

// send to server.

}

This all happens when a button is clicked by the way.


I get stuff like this
cells[1].val is not a function
http://localhost:4791/Planner/Javascripts/Planner/Planner.js
Line 275
var test = cells[1].val();


So I am guessing I am missing a step.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

var test = cells[1].val();



When you use the array operator ([]) on a jQuery wrapped set what do you get back? Another wrapped set? No. You get a DOM element.

And .val() is a method of the jQuery wrapped set, and not of DOM elements, so you get the error.

Also, in your initial expression (the one with all the .parent() calls) there's an easier way to do that. Hint: .parent() isn't the only method that performs ancestor traversal.
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

var test = cells[1].val();



When you use the array operator ([]) on a jQuery wrapped set what do you get back? Another wrapped set? No. You get a DOM element.

And .val() is a method of the jQuery wrapped set, and not of DOM elements, so you get the error.

Also, in your initial expression (the one with all the .parent() calls) there's an easier way to do that. Hint: .parent() isn't the only method that performs ancestor traversal.



Ic and how do I use this DOM element?

I am not sure what could be used instead there seems too be quite alot of them.
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah ic for the first part I have to use stuff like innerHTML?

Second part I am still not sure off.
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, not sure where you are going with that...

In order to use .val() you need a wrapped set. So if you have a DOM element you can wrap it in $() to create a new wrapped set, or you could look into using a method like eq().

Also, check out the .parents() method.


 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Hmm, not sure where you are going with that...

In order to use .val() you need a wrapped set. So if you have a DOM element you can wrap it in $() to create a new wrapped set, or you could look into using a method like eq().

Also, check out the .parents() method.




Oh I did not know you can wrap the returned object to make it usable with jquery again. I am not sure what you mean by "Hmm, not sure where you are going with that..." if your talking about the innerHTML it seems to have the value of the cell and that's really all I am after.

So is doing .parents() faster then doing it the way I am doing or is just less code?
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Yes.



K I will remember that for the next time.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic