www.webdeveloper.com
Results 1 to 4 of 4

Thread: please help me. i want to limit it

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    6

    please help me. i want to limit it

    i have this txt file name contacts.txt that contains this:

    kate|female|kathryn bailey beckinsale|26-jul-1973|#23 underworld drive|(621) 142-7827|kate@lycans.net
    jessica|female|jessica claire biel|03-mar-1982|27 texas avenue|(53)2344223|jbiel@yahoo.com
    johnny|male|john christopher depp ii|09-jun-1963|711 pirate road|(773) 476-6634|jsparrow@piratebay.org


    my script is this:

    function syncText() {
    var xhr = new XMLHttpRequest();

    xhr.open("get", "data/contacts.txt", false);

    xhr.send(null);

    if (xhr.status == 200) {
    var data = xhr.responseText;
    var items = data.split("|");
    items.sort();

    var div = document.getElementById("header2");
    for (var i = 0; i < items.length; i++) {
    var p = document.createElement("p");
    var text = document.createTextNode(items[i]);
    p.appendChild(text);
    div.appendChild(p);
    }
    } else {
    alert("data retrieval failed...");
    }
    }


    html

    <div id="header2">
    <button onclick="syncText()">Pak</button>
    </div>

    i only want to retreive kat, jessica, johnny.. please help me

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    You have, at first, to split your file with the lines !

  3. #3
    Join Date
    Feb 2013
    Posts
    6
    yes but no... the txt file must not be edited... is there any other way?

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Actually your lines var items = data.split("|"); and items.sort(); mix all without distinguishing the mail of kate and the pseudo of jessica ! It makes no sense to try to classify all different fields !

    You have at first to build an array with the different lines.
    Then you will be able to split in a loop the seven items : pseudo, sex, name, date, addres1, adress2, mail and store all this fields in an array of objects without edition...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles