PDA

View Full Version : Need Help - Get Url based on date then pass it to table



tnarg
11-09-2008, 03:10 PM
1) Script Title: Get Url based on date then pass it to table

2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...

3) Describe problem:

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

jscheuer1
11-09-2008, 03:51 PM
Warning: Please include a link to the DD script in question in your post. See this thread (http://www.dynamicdrive.com/forums/showthread.php?t=6) for the proper posting format when asking a question.

Please post a link to the page on your site that contains the problematic code so we can check it out.