SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    ul list to array in jquery

    I'm trying to get a UL list into an array so i can put it into different form fields

    HTML Code:
    <ul id="AddressInfo">
          <li> 123 Main St. </li>
          <li> Brooklyn </li>
          <li> 11214 </li>
    </ul>
    i tried doing this
    $(".myUL").click(function () {

    // $('#mytext').val($(this).text());

    var getMyUL
    getMyUL = $(this).text();

    var arr = getMyUL.split(' ');
    alert(arr[0]);
    $('#Address').val(arr[1]);
    $('#ApartmentNumber').val(arr[2]);

    });

    and the above doesn't work in IE :/

    but it just way to unstable.. i was reading Jquery has toArray but not sure how to do it. I'm a php developer so i'm thinking how to do it in php lol
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    You can use $('li', this) which gives you the list items as an indexable array.

    For example:

    Code javascript:
    $(".myUL").click(function () {
        var address = $('li', this),
            street = $(address[0]).text(),
            suburb = $(address[1]).text(),
            postcode = $(address[2]).text();
     
        ...
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    interesting.. so... it automatically puts it into an array? based on your example i was over thinking it.
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •