javascript - How would I display all elements in an array in HTML as clickable objects? -
so have produced small script in javascript shown:
var txtfile = new xmlhttprequest(); txtfile.open("get", "http://www.drakedesign.co.uk/mdmarketing/uploads/date.txt", true); txtfile.onreadystatechange = function() { if (txtfile.readystate === 4) { // makes sure document ready parse. if( (txtfile.status == 200) || (txtfile.status == 0) ) { // makes sure it's found file. alltext = txtfile.responsetext; arrayoflines = alltext.match(/[^\r\n]+/g); document.getelementbyid("date").innerhtml = arrayoflines[0]; filename1 = (arrayoflines[0] + ".csv"); res1 = filename1.replace("/","-"); res2 = res1.replace("/","-"); urlcsv = ("http://www.drakedesign.co.uk/mdmarketing/uploads/" + res2); } } }; txtfile.send(null);
the above code simple parses text document updated weekly: http://www.drakedesign.co.uk/mdmarketing/uploads/date.txt
which has dates within written line line so:
16/04/16
09/04/16
02/04/16...
i here ask how convert above script parse text document , display each element in html document , making visual element clickable take me correct date.
am going wrong way? there more efficient way it? @ point considering hard coding possible dates appear. rather dynamically!
thank in advance offers help.
ps: using jquery! sorry forgot mention before.
you didn't include jquery
tag in question i'm going assume you're looking plain javascript answer. each date receive in response, can turn link
, clickable on page.
something this:
function createlink(text, url, parentelement) { var = document.createelement('a'); var linktext = document.createtextnode(text); a.appendchild(linktext); a.href = url; parentelement.appendchild(a); }
then can use helper create many links like:
createlink('16/04/16', 'http://www.hello.com/16/04/16', document.body);
Comments
Post a Comment