Jump to content

Gilbert

Members
  • Content count

    8
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Gilbert

  • Rank
    Newbie
  1. How do I invoke multiple functions automatically

    Hey iwato, thanx for your quick response - I only had time to have a sandwich. I thought that 'XMLHttpRequest' was a reserved word - as a constructor or like. I will give it a whirl and let you know. How do I award a trophy. I asked another responder how to mark a post as answered and he said people just change the title of their request to 'solved'. Can you give me a heads up on that? thanks, Gil I have changed the variable names to separate the 2 functions. Still the same - I see what you were saying, but I figured one function would be done before the other took effect. Here's what I've got now. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Service Club Collections</title> <style> .wholePage { position: relative; width: 1350px; height: 2000px; border: 2px solid red; margin:auto;} .scColl { position:absolute; top:0; left:0; width:1050px; height:2000px; border:2px solid red;} .scTot { position: absolute; top: 0; right: 0; width: 250px; height: 2000px; border: 2px solid red;} #collections { position:absolute; top:0; left:0;} #totals { position:absolute; top:0; right:0;} table, th, td { border: 1px solid red; border-collapse: collapse;} th, td { padding: 7px 10px;} th { font-size:14px; color: firebrick;} td { font-size:12px; color: darkolivegreen; text-align: center;} </style> </head> <body> <a href="ringerinfo.html" type="button" style="margin:auto">Return</a> <div class="wholePage"> <div class="scColl"> <table id="collections"></table> </div> <div class="scTot"> <table id="totals"></table> </div> </div> <script> (function loadXMLCollDoc() { var xmlhttpcoll = new XMLHttpRequest(); xmlhttpcoll.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttpcoll.open("GET", "datafiles/servClubColl.xml", true); xmlhttpcoll.send(); })(); function myFunction(xmlcoll) { var i; var xmlCollDoc = xmlcoll.responseXML; var table ="<tr><th>Service Club</th><th>Ring Date</th><th>Location</th><th>Start Time</th><th>End Time</th><th>Total Bills</th><th>Total Coins</th><th>Total Checks</th><th>Total Kettle</th></tr>"; var x = xmlCollDoc.getElementsByTagName("scCollections"); for (i = 0; i <x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("RingerName")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("RingDate")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Location")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedStart")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedEnd")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Bills")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Coins")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Checks")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("AmountCollected")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("collections").innerHTML = table; } (function loadXMLTotDoc() { var xmlhttptot = new XMLHttpRequest(); xmlhttptot.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttptot.open("GET", "datafiles/scTotals.xml", true); xmlhttptot.send(); })(); function myFunction(xmltot) { var i; var xmlTotDoc = xmltot.responseXML; var table = "<tr><th>Service Club</th><th>Seasonal Total</th></tr>"; var x = xmlTotDoc.getElementsByTagName("Totals"); for (i = 0; i < x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("ServClub")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("TotalAmount")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("totals").innerHTML = table; } </script> </body> </html>
  2. Hi, I've made an html page that invokes a function automatically ( using the parentheses b/4 & after ) to make a table from an XML file. It worked great with a little help from you guys. I then made another one to read a different XML file and that worked great. I want to put both tables on the same page so I made a couple of 'divs' and positioned each in a column formation. That part seems to work well, but I am calling the 2 functions to make the tables consecutively and it doesn't work as I wanted. When I open this file in a browser, as it is here, I get only the second table in the second column correctly; and if I comment out the second table, I get only the first table in the first column correctly. I've included the code below; I hope someone can tell me how to do this. Also just a sample of the 2 XMLs I'm trying to display. Do I need a wrapper function with the others invoked from it, or something like that. Thanks <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Service Club Collections</title> <style> .wholePage { position: relative; width: 1350px; height: 2000px; border: 2px solid red; margin:auto;} .scColl { position:absolute; top:0; left:0; width:1050px; height:2000px; border:2px solid red;} .scTot { position: absolute; top: 0; right: 0; width: 250px; height: 2000px; border: 2px solid red;} #collections { position:absolute; top:0; left:0;} #totals { position:absolute; top:0; right:0;} table, th, td { border: 1px solid red; border-collapse: collapse;} th, td { padding: 7px 10px;} th { font-size:14px; color: firebrick;} td { font-size:12px; color: darkolivegreen; text-align: center;} </style> </head> <body> <a href="ringerinfo.html" type="button">Return</a> <div class="wholePage"> <div class="scColl"> <table id="collections"></table> </div> <div class="scTot"> <table id="totals"></table> </div> </div> <script> (function loadXMLCollDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttp.open("GET", "datafiles/servClubColl.xml", true); xmlhttp.send(); })(); function myFunction(xmlcoll) { var i; var xmlDoc = xmlcoll.responseXML; var table ="<tr><th>Service Club</th><th>Ring Date</th><th>Location</th><th>Start Time</th><th>End Time</th><th>Total Bills</th><th>Total Coins</th><th>Total Checks</th><th>Total Kettle</th></tr>"; var x = xmlDoc.getElementsByTagName("scCollections"); for (i = 0; i <x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("RingerName")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("RingDate")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Location")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedStart")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedEnd")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Bills")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Coins")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Checks")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("AmountCollected")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("collections").innerHTML = table; } (function loadXMLTotDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttp.open("GET", "datafiles/scTotals.xml", true); xmlhttp.send(); })(); function myFunction(xmltot) { var i; var xmlDoc = xmltot.responseXML; var table = "<tr><th>Service Club</th><th>Seasonal Total</th></tr>"; var x = xmlDoc.getElementsByTagName("Totals"); for (i = 0; i < x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("ServClub")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("TotalAmount")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("totals").innerHTML = table; } </script> </body> </html> Here is just a sample of the XML data files *********************************** <?xml version='1.0' encoding='utf-8'?> <dataroot> <scCollections> <RingerName>1st National bank scotia</RingerName> <RingDate>Dec 12 - Mon</RingDate> <Location>Price Chopper Niskayuna Left Door</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>9:00 pm</SchedEnd> <Bills>$ 243</Bills> <Coins>$ 27</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 270</AmountCollected> </scCollections> <scCollections> <RingerName>Advisory Board</RingerName> <RingDate>Dec 9 - Fri</RingDate> <Location>Co-Op Nott St Niskayuna</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>1:00 pm</SchedEnd> <Bills>$ 131</Bills> <Coins>$ 15</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 146</AmountCollected> </scCollections> <scCollections> <RingerName>Beukendall Eastern Star</RingerName> <RingDate>Dec 7 - Wed</RingDate> <Location>Price Chopper Glenville Main Dr</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>7:00 pm</SchedEnd> <Bills>$ 283</Bills> <Coins>$ 64</Coins> <Checks>$ 100</Checks> <AmountCollected>$ 447</AmountCollected> </scCollections> <scCollections> <RingerName>Beukendall Eastern Star</RingerName> <RingDate>Dec 8 - Thu</RingDate> <Location>Price Chopper Glenville Main Dr</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>7:00 pm</SchedEnd> <Bills>$ 415</Bills> <Coins>$ 38</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 453</AmountCollected> </scCollections> </dataroot> AND ********************************* <?xml version='1.0' encoding='utf-8'?> <dataroot> <Totals> <ServClub>1st National bank scotia</ServClub> <TotalAmount>$ 270</TotalAmount> </Totals> <Totals> <ServClub>Advisory Board</ServClub> <TotalAmount>$ 146</TotalAmount> </Totals> <Totals> <ServClub>Beukendall Eastern Star</ServClub> <TotalAmount>$ 900</TotalAmount> </Totals> <Totals> <ServClub>Corps Band</ServClub> <TotalAmount>$ 190</TotalAmount> </Totals> <Totals> <ServClub>General Electric Volunteers</ServClub> <TotalAmount>$ 2505</TotalAmount> </Totals> </dataroot>
  3. XML not working - can't see what's wrong

    Thank you so much for your reply. Sorry it took so long to get back to you - it seems I don't get an email when someone replies. Both of your answers worked out perfectly and I can now do the XML with no problems. Just for future reference, I don't know why the file I copied came out like triple spaced. I copied and pasted - is there a better way? And I don't see where to mark this question as answered. In other forums they usually have a button right here that says 'answered'. Thanx again dsonesuk!
  4. JSON question - simple

    Hi, I've read the json tutorial on w3 website, and just have one question which makes a huge difference in the way I create the layout of my json file. All the examples they gave had a very short json file to read, but how does a json file look when you're trying to read many records. Does each httpRequest read the whole file from one first '{' to the last '}' and that's it. Or, if there are several, {'s will it return each one as an object. It was unclear to me from the tutorials. Specifically, If I had a database with 10 records and 5 fields in each, would I do this: { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" }..... etc for 10 times, or would I do this with a name for my 'database' and make an array of the records: { databaseName [ { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } { "name1" : "value1", "name2" : "value2", "name3" : "value3", "name4" : "value4", "name5" : "value5" } .......etc to 10 records as an array ] } I think I'm understanding it as the second example - is this correct or am I missing something? Would it be all right to put 500 records in an array? I don't know how often they update the w3 website, but maybe they could emphasize this better. I know they went into creating the json file from a database using php and some other methods, but I want to create it myself and then upload the file to the server. One other question is that in the tutorial it said a json file has a json file type, but then they used a file in the example with a .txt type. I know json files are text files; but can you use .txt on your json file?
  5. I copied and pasted a file from the w3 tutorial XML/AJAX application but changed just a couple of spots so it could read my own XML data file. It doesn't work - what am I missing, please. When I open the console in either google or IE it says xmlDoc is null or undefined - somehow I'm not 'reading' the file or something? can anybody explain it more. I've read over the toturials a couple of times and I think it should be working. I have also cleaned out the cach in the browser by hitting cntrl F5, which I learned from someone along the way. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>S.C. Information</title> <style> table, th, td { border: 1px solid green; border-collapse:collapse; } th, td { padding: 5px; } </style> </head> <body> <button type="button" onclick="loadXMLDoc()">Get my S.C. Report</button> <br><br> <table id="demo"></table> <script> function loadXMLDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttp.open("GET", "scTotals.xml", true); xmlhttp.send(); } function myFunction(xml) { var i; var xmlDoc = xml.responseXML; var table="<tr><th>Service Club</th><th>Seasonal Total</th></tr>"; var x = xmlDoc.getElementsByTagName("Totals"); for (i = 0; i <x.length; i++) { table += "<tr><td>" + x.getElementsByTagName("ServClub")[0].childNodes[0].nodeValue + "</td><td>" + x.getElementsByTagName("TotalAmount")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("demo").innerHTML = table; } </script> </body> </html> Data File 'scTotals.xml' in same website folder. <?xml version='1.0' encoding='utf-8'?> <dataroot> <Totals> <ServClub>Beukendall Eastern Star</ServClub> <TotalAmount>$ 447</TotalAmount> </Totals> <Totals> <ServClub>Key Club</ServClub> <TotalAmount>$ 363</TotalAmount> </Totals> <Totals> <ServClub>S.I. Group</ServClub> <TotalAmount>$ 201</TotalAmount> </Totals> <Totals> <ServClub>Sarah Bilofsky & Friends</ServClub> <TotalAmount>$ 182</TotalAmount> </Totals> <Totals> <ServClub>Schenectady ARC</ServClub> <TotalAmount>$ 1530</TotalAmount> </Totals> </dataroot> Any help would be appreciated. Gil
  6. Using AJAX to get info from XML file

    Thank you very much justsomeguy - that really helped 'splain it. I'll mark this as answered if I can find where to do it.?
  7. Using AJAX to get info from XML file

    Hey, justsomeguy - thanx for your response. I'm am a little hazy ( actually a lot hazy ) on the whole server thing. I thought I read someplace that if your data file (xml) was in the same folder as your html file that it would work ok. I've tried putting the whole path for my xml file, like c:\ learningwebdesign\myhtml etc, etc but it still doesn't work. Do I need to download a server just to experiment with a few things and which ones would you recommend. It seems like I've read a thousand pages about servers, but they seem to talk to the experienced developer instead of the beginner and I am still wondering if I 'need' a server on my computer before I'm ready to publish to a hosted website. Can you recommend some server software that will accomplish what I need here, which is just to see if my code works. Actually the 'code' works - I just can't get to the data it seems. I know you may be saying that my syntax might be wrong or something like that, but I copy & pasted a couple of programs and they don't work on my set up either. I hope I've explained what it is I need - Thanks for any help..... Gil
  8. Hi all, I'm just starting to get into website design, tho' I've been a programmer for many years. I've got a site going pretty well, but I really want to update the information on the site every day using tables. I am studying the AJAX/XML method and I think I must be missing something. After using the 'display CD collection' as a model, I couldn't get it to work. So then I tried copying & pasting the actual files from the example ( they list the xml file for your reference ) into a folder and Opened it with a google browser. I can get the button that says 'create my CD collection', but nothing happens when I click it. What am I missing; is there another article that might explain this in more detail and say exactly what's going on? Thanks
×