Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery: Traversing up, over and down

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30228
    brianatlarge
    Member

    I’ve got several forms on one page and I want to validate whether or not one of the fields on the form that is being submitted is filled in or not.

    Basically my form looks like this:









    White Shirt
    Quantity:
    Price: $29




    So my thought process was, select THIS, which would be the submit button, then use closest() to go up the tree to the table, then go back down to .quantity, and get the value of that.


    function checkform() {
    alert($(this).closest('table').children('.quantity').val());
    }

    Unfortunately, the only thing I’m getting is “undefined”. What’s the proper way to traverse to get what I’m looking for?

    #79900
    jamygolden
    Member

    Try:

    function checkform() {
    alert($(this).closest('table').find('.quantity').val());
    }
    #79666
    brianatlarge
    Member

    That didn’t work.

    I also thought about changing it to .closest(‘form’), since table is on the same level as the submit button, but that didn’t make any difference. I also tried it with the .find() that you suggested, and still no luck.

    Any other suggestions?

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.