Jump to content

Jon JC

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Jon JC

  1. It looks like you're right.Something I noticed is that the code works in Internet Explorer but not in Mozilla Firefox. I like using Firefox, so I've been trying to make it work by using the 'setTimeout' function and FOR loops to give AJAX enough time to execute. However, I haven't been successful.Any ideas?JC
  2. Fast response Thanks for trying.Anyone else with ideas?JC
  3. Yea, I am always writing to row 0. However, when a new row 0 is inserted into a table, the rest of the rows (and data in those rows) are pushed down the table (i.e. all the data is still present and nothing should have been overwritten).I got the idea above from an example in the HTML DOM tutorial:http://www.w3schools.com/js/tryit.asp?file...table_insertrowI also tried your suggestion, but I got a similar result: only the contents of the last file shows up in the table.Attached below is some executable code (4 files: 0_archive.js, 1_archive.js, test.html, test.js). Hopefully it will help!JC0_archive.js abc 1_archive.js def test.html <html><head><script src="test.js"></script></head><body><table><tr> <td> <input type="radio" name="year" value="2006" onClick="getBlog()"> Click Me </td></tr></table><table id="table" border="1"></table></body></html> test.js var xmlHttpfunction getBlog(){var ifor (i=0;i<2;i++){ var tableRow=document.getElementById("table").insertRow(0) var tableCell=tableRow.insertCell(0) var url=i + "_archive.js" xmlHttp=GetXmlHttpObject(stateChanged) xmlHttp.open("GET", url , true) xmlHttp.send(null)}}function stateChanged() {if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ var tableCell=document.getElementById("table").rows[0].cellstableCell[0].innerHTML=xmlHttp.responseText} }function GetXmlHttpObject(handler){ var objXmlHttp=nullif (navigator.userAgent.indexOf("Opera")>=0){alert("This example doesn't work in Opera") return }if (navigator.userAgent.indexOf("MSIE")>=0){ var strName="Msxml2.XMLHTTP"if (navigator.appVersion.indexOf("MSIE 5.5")>=0){strName="Microsoft.XMLHTTP"} try{ objXmlHttp=new ActiveXObject(strName)objXmlHttp.onreadystatechange=handler return objXmlHttp} catch(e){ alert("Error. Scripting for ActiveX might be disabled") return } } if (navigator.userAgent.indexOf("Mozilla")>=0){objXmlHttp=new XMLHttpRequest()objXmlHttp.onload=handlerobjXmlHttp.onerror=handler return objXmlHttp}}
  4. Hi,I want to use a FOR loop to include the content of multiple files into a table. Within each iteration, a new row is created and external text is loaded using an AJAX technique.When the function is executed, only contents of the last file appear in the table. It seems the files contents are overwriting each other (possibly in the same cell). I want each cell to contain contents from different files.Here is the relevant JS code: var xmlHttpfunction getBlog(){var ifor (i=1;i<3;i++){var archiveRow=document.getElementById("archiveBlogTable").insertRow(0)var archiveCell=archiveRow.insertCell(0)var url=i + "_archive.js"xmlHttp=GetXmlHttpObject(stateChanged)xmlHttp.open("GET", url , true)xmlHttp.send(null)}} function stateChanged() {if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ var archiveBlog=document.getElementById("archiveBlogTable").rows[0].cellsarchiveBlog[0].innerHTML=xmlHttp.responseText} } Any ideas?Note: I did not include the GetXmlHttpObject function since it focuses on browser error handling and does not affect my goal. Also, much of this code can be found in the AJAX tutorial (http://www.w3schools.com/ajax/ajax_source.asp).JC
  5. Got it to work.Thanks Chocolate.JC
  6. Hi,I want to include an external text (or .js/.html) file into a specific section of an HTML page. This is what I have right now:<script type="text/javascript">function changeText(){var cell=document.getElementById('textLocation').rows[0].cellscell[0].innerHTML="<script src=\"ExternalText.js\"></script>"}</script>This obviously does not work. I think it is because the <srcipt> tag does not support nested <script> tags. Any ideas?JC
×
×
  • Create New...