<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Help: Get data from url and write to table' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Help: Get data from url and write to table' posted on the 'JavaScript' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Thu, 20 Jun 2013 04:21:27 -0700</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 04:21:27 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Help: Get data from url and write to table</title>
      <link>http://www.programmersheaven.com/mb/java-script/413827/413827/help-get-data-from-url-and-write-to-table/</link>
      <description>Hi everyone,&lt;br /&gt;
&lt;br /&gt;
First, I am not a programmer so be gentile. I need some help getting data from a url and placing it into a table. I am trying to get the daily threshold securities list that is published daily on the nasdaq site. The data published today is for yesterday's threshold securities. The url changes everyday according to the date eg: &lt;a href="http://www.nasdaqtrader.com/dynamic/symdir/regsho/nasdaqth20100222.txt."&gt;http://www.nasdaqtrader.com/dynamic/symdir/regsho/nasdaqth20100222.txt.&lt;/a&gt; The script that I managed to hack together does get the correct url everyday, but I am unable to insert the data into a dynamically created table. Here is what I have so far:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;ShoList&amp;lt;/title&amp;gt;
&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;

//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='&amp;lt;table id="theListTable" border="1" width="800" bordercolor="#DBDBDB" cellpadding="2" style="border-collapse:collapse;"&amp;gt;';
            var tmp;
            var val;
            var txt;
			var strText;
            for (var idx=0;idx&amp;lt;tmpArr.length;idx++) {
                tmp=tmpArr[idx].split('|');
               /* out += '&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;'+tmpArr[idx]+'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;';*/
				strText= '&amp;lt;tr&amp;gt;';
				for (var intTmp=0;intTmp&amp;lt;tmp.length;intTmp++)
				{
					if (intTmp&amp;lt;5){
					txt = tmp[intTmp].replace('"','');
					strText= strText + '&amp;lt;td&amp;gt;'+txt+'&amp;lt;/td&amp;gt;';
					}
				}
				/*{
					if (intTmp&amp;lt;tmp.length -1){
						if (intTmp&amp;lt;5){
						txt = tmp[intTmp].replace('"','');
						strText= strText + '&amp;lt;td&amp;gt;'+txt+'&amp;lt;/td&amp;gt;';
						}
					else 
						txt = tmp[intTmp].replace('"','')
						txt=''
						strText= strText + '&amp;lt;td&amp;gt;'+txt+'&amp;lt;/td&amp;gt;';
						parent.shoDate=txt
					}
				}*/
				out += strText + '&amp;lt;/tr&amp;gt;';
            }
            out += '&amp;lt;/table&amp;gt;';
            document.getElementById('theList').innerHTML=out;
        }
    }

}

&amp;lt;/script&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;
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&amp;lt;10)
day="0"+ day

if (month&amp;lt;10)
month="0"+ month

/*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)

}


&amp;lt;/script&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
&amp;lt;!--
/* CSS Document */
.contenttext {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	font-weight: normal;
	text-transform: none;
	color: #333333;
}
.titletext {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	text-transform: uppercase;
	color: #333333;
}

--&amp;gt;
&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body onload="getFile(getFileUrl(),'makeTable');"&amp;gt;
&amp;lt;div class="contenttext" id="theList"&amp;gt;Loading...&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt; &lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/413827/413827/help-get-data-from-url-and-write-to-table/</guid>
      <pubDate>Wed, 24 Feb 2010 04:21:22 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: Help: Get data from url and write to table</title>
      <link>http://www.programmersheaven.com/mb/java-script/413827/414079/re-help-get-data-from-url-and-write-to-table/#414079</link>
      <description>I don't think ajax will work cross domain, so you'll need to call a script on your own website to get the data, or you might be able to use an iframe, but I think then you can't manipulate it's contents if it's on another domain as well...&lt;br /&gt;
&lt;br /&gt;
To answer the question of reading data from the url and placing it in a table you could do something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
  &amp;lt;meta http-equiv="content-type" content="text/html; charset=windows-1250"&amp;gt;
  &amp;lt;meta name="generator" content="PSPad editor, www.pspad.com"&amp;gt;
  &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
  &amp;lt;script type="text/javascript"&amp;gt;
   function createTable() {
      var params = document.location.search.substr(1).split('&amp;amp;');
      var table  = document.createElement('table');
      var tbody  = document.createElement('tbody');
      table.appendChild(tbody);
      for(var i=0;i&amp;lt;params.length;i++) {
         var pair = params[i].split('=');
         var tr1 = document.createElement('tr');
         var td1 = document.createElement('td');
         var td2 = document.createElement('td');
         td1.innerHTML = pair[0];
         td2.innerHTML = pair[1];
         tr1.appendChild(td1);
         tr1.appendChild(td2);
         tbody.appendChild(tr1);
      }
      document.getElementById('container').appendChild(t
able)
   }



  &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;div id="container"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;script type="text/javascript"&amp;gt;
   // this script strips everything after ? and puts the fields in the first td and the value in the second td
   //
   createTable();
  &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;img src="http://www.programmersheaven.com/images/Community/twink.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
-mac-&lt;br /&gt;
mailto:mac_doggie@hotmail.com&lt;br /&gt;
the Netherlands...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/413827/414079/re-help-get-data-from-url-and-write-to-table/#414079</guid>
      <pubDate>Mon, 01 Mar 2010 14:04:06 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: Help: Get data from url and write to table</title>
      <link>http://www.programmersheaven.com/mb/java-script/413827/414142/re-help-get-data-from-url-and-write-to-table/#414142</link>
      <description>Hi mac, Thanks for trying but I still can't get the info from the URL to a table. As I said before I am not a programmer and there are a lot of things that I just don't understand, I'm trying to learn. The script that I posted gives me the correct URL daily, but it writes the URL to the page instead of taking the contents of that URL and creating a table with them.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/413827/414142/re-help-get-data-from-url-and-write-to-table/#414142</guid>
      <pubDate>Tue, 02 Mar 2010 10:20:36 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: Help: Get data from url and write to table</title>
      <link>http://www.programmersheaven.com/mb/java-script/413827/414227/re-help-get-data-from-url-and-write-to-table/#414227</link>
      <description>if you have the URL in your page, is it inside a div tag like:&lt;br /&gt;
&amp;lt;div id="contentsofothersite"&amp;gt;&lt;br /&gt;
http://www.somesite.com?variable1=value1&amp;amp;variable2=value2&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
??&lt;br /&gt;
&lt;br /&gt;
If this is the case you can use javascript to grab that line of text and split it up into pieces. You can use my example, but replace the document.location.search with documentGetELementById('contentsofothersite').inne
rHTML&lt;br /&gt;
&lt;br /&gt;
where contentsofothersite is the ID of the div element that the URL is in.&lt;br /&gt;
&lt;br /&gt;
hope this helps you out...&lt;br /&gt;
&lt;img src="http://www.programmersheaven.com/images/Community/twink.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
-mac-&lt;br /&gt;
mailto:mac_doggie@hotmail.com&lt;br /&gt;
the Netherlands...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/413827/414227/re-help-get-data-from-url-and-write-to-table/#414227</guid>
      <pubDate>Fri, 05 Mar 2010 11:17:51 -0700</pubDate>
      <category>JavaScript</category>
    </item>
  </channel>
</rss>