Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Need Help - Get Url based on date then pass it to table
Old 11-11-2008, 04:44 PM Need Help - Get Url based on date then pass it to table
Novice Talker

Posts: 9
Trades: 0
I'll try to explain... I need to put a txt file into a table automatically. To get the file I must first find the URL witch changes everyday, ie: www.someurl.com/dir/dir/date. I managed to hack together a script that gets me the correct Url. Now how do I put the result into a table??

Here is the code to get the URL:

<script type="text/javascript">
function getFileUrl(){
/*First, get the current date*/
var currentTime = new Date();

/*because shoLists are published only at midnight during the workweek, we must subtract 1 from the day
In the case of Sunday, we subtract two, and Monday, subtracdt 3 in order to get Friday's list*/
var intNB = 1
if(currentTime.getDay() == 0)
{
intNB=2;
}
else if(currentTime.getDay() == 1)
{
intNB = 3;
}
else
{
intNB = 1;
}

/*We now need to subtract the number from the day to get the right date (Year, month, and day)*/
var day = currentTime.getDate() - intNB;
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();

/*If the day is less than ten, we must add a 0 to make the day a two digit number*/
if (day<10)
day="0"+ day

/*Finally, we must put it all togther to create the proper URL to get the shoList file */
var shoDate=year + '' + month + '' + day

var strUrl='http://www.nasdaqtrader.com/dynamic/symdir/regsho/nasdaqth'
var strTxtUrl=strUrl+shoDate+'.txt'
/*
getFileURL=strTxtUrl


TEST*/
document.write(strTxtUrl)

}
</script>


Here is the code to make the table:

<script type="text/javascript">
//create the Cross-browser XMLHttpRequest object
function getFile(pURL,pFunc) {
if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
xmlhttp=new XMLHttpRequest();
eval('xmlhttp.onreadystatechange='+pFunc+';');
xmlhttp.open("GET", pURL, true); // leave true for Gecko
xmlhttp.send(null);
} else if (window.ActiveXObject) { //IE
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
if (xmlhttp) {
eval('xmlhttp.onreadystatechange='+pFunc+';');
xmlhttp.open('GET', pURL, false);
xmlhttp.send();
}
}

}

function makeTable() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
var tmpArr=xmlhttp.responseText.split('\n');
var out='<table id="theListTable" border="1" width="800" bordercolor="#DBDBDB" cellpadding="2" style="border-collapse:collapse;">';
var tmp;
var val;
var txt;
var strText;
for (var idx=0;idx<tmpArr.length;idx++) {
tmp=tmpArr[idx].split('|');
/* out += '<tr><td>'+tmpArr[idx]+'</td></tr>';*/
strText= '<tr>';
for (var intTmp=0;intTmp<tmp.length;intTmp++)
{
if (intTmp<5){
txt = tmp[intTmp].replace('"','');
strText= strText + '<td>'+txt+'</td>';
}
}
/*{
if (intTmp<tmp.length -1){
if (intTmp<5){
txt = tmp[intTmp].replace('"','');
strText= strText + '<td>'+txt+'</td>';
}
else
txt = tmp[intTmp].replace('"','')
txt=''
strText= strText + '<td>'+txt+'</td>';
parent.shoDate=txt
}
}*/
out += strText + '</tr>';
}
out += '</table>';
document.getElementById('theList').innerHTML=out;
}
}

}

</script>


And then the body:

<body onload="getFile(getFileUrl(),'makeTable');">
<div class="contenttext" id="theList">Loading...</div>
</body>

I would appreciate any help, thanks
tnarg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Need Help - Get Url based on date then pass it to table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09092 seconds with 12 queries