PDA

View Full Version : Limiter



RakiZtahX
02-05-2013, 04:10 PM
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>


and my problems is how to select only the name in the contacts.txt (i only want kate, jessica, johnny) to be shown and not all.. please help...

RakiZtahX
02-08-2013, 03:11 PM
why is there no reply in my post?? is there nobody out there?

james438
02-08-2013, 05:17 PM
It looks like a valid post. You seem to ask your question clearly although keyboard1333 had to clean up your post somewhat to make it readable. It might help to give your thread a more descriptive title. Other than that sometimes people are just busy with other posts and occasionally some posts get neglected. It happens. In my experience this is most likely to happen in the MySQL forum and much less likely to happen in the javascript forum. Speaking for myself, I have not answered your thread because I am not knowledgeable in javascript.

At first glance this looks like it could easily be solved using php with an explode() function of the pipe symbol and the line break. This type of information looks better suited to being stored in a database as well. How do you plan on using this information? I am not saying that I am going to answer your question, especially since I have only dabbled a little bit with javascript in the past, but answering that might help someone else who is looking at this thread. What have you tried so far to solve this?