Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    .sort() customized function - Works in IE (surprisingly) but not FF

    Hello, everyone.

    This is using jQuery v1.7.2.

    I have a multiple SELECT that is dynamically populated with names (first last), and a button that will check to see if any of the selected names are already in a DIV - if so, do nothing; if not, add the name(s) to the DIV, each separated by "<BR>", and then sort by last name (split on the "<BR>", sort, join with "<BR>".)

    Here is some of my code:
    <div id="addedDevs"></div> <!-- If names are already in database, they will be retrieved and populated in here -->

    Now for some of the JS code. I'm only posting the one (very long) line that is pertinent. I'll push it across several lines to lessen confusion.

    Code:
    $('#addedDevs').html($('#addedDevs').html().split("<BR>").sort(
    function(a,b){
      a+=""; b+="";
      A = a.substring(a.indexOf(" ")+1);
      B = b.substring(b.indexOf(" ")+1);
      return A>B ? 1 : A<B ? -1 : 0 ;
    }
    ).join("<BR>"));
    Any idea why it would work in IE, but not FF? I have not tested in Chrome.

    I'm heading home for the weekend, but will be back in the office Monday morning, not-bright-eyed, not-bushy-tailed, but at least alert enough to answer any questions.

    Have a great weekend, everyone.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Perhaps its <br> in FF. I think we can use a regex /\<br\>/i in split() but I'm too tired to check at the min . You could account for <br /> in the regex as well, just in case.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I thought all browsers converted <br /> to <BR>. But I'll give your suggestion a shot and see what happens.

    Thanks!
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Nope.

    Actually, now that I think about it, my original post wasn't very descriptive.

    In IE, when a name is added to the field it is sorted alphabetically by last name (or, to be precise, anything after the first space of the value entered.) In FF, the name is added, but the sorting by jQuery isn't working.. whatever name is selected is just tacked on to the end.

    I would love to post all my code, but my dev system is isolated from the internet, and I do not have the proper permissions to burn anything to CD. Flash drives are proscribed. I should put that in my sig.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    AH.. I tweaked it a bit and it's now working. Thanks, Andrew! You nailed it.

    Code:
    .split(/(<br[^>]*>)/gi);
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Could a moderator please mark this thread as RESOLVED? I no longer have the option to edit the original post. Thanks.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

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