Advertisement
UrQuan

HW JS2 Pr3

Mar 24th, 2015
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tableCD(xh){
  2.   x = JSON.parse(xh.responseText);
  3.   var txt,x,xx,i;
  4.   txt = "<table border='1'><tr><th>Title</th><th>Artist</th></tr>";
  5.   for( i=0; i<x.CD.length; i++ ) {
  6.     txt=txt + "<tr>";
  7.     txt=txt + "<td>" + x.CD[i].TITLE + "</td>";
  8.     txt=txt + "<td>" + xx=x.CD[i].ARTIST + "</td>";
  9.     txt=txt + "</tr>";
  10.   }
  11.   txt=txt + "</table>";
  12.   document.getElementById('txtCDInfo').innerHTML = txt;
  13. }
  14.  
  15. function averageCD(xh){
  16.   x = JSON.parse(xh.responseText);
  17.   var txt,x,xx,i;
  18.   xx=0;
  19.   txt = "Total of all prices: ";
  20.   for( i=0; i<x.CD.length; i++ )
  21.         xx+=parseFloat(x.CD[i].PRICE);
  22.   txt += parseInt(xx*100)/100;
  23.   xx = xx/x.CD.length
  24.   txt += ", and the average: " + parseInt(xx*100)/100;
  25.   document.getElementById('txtCDInfo').innerHTML = txt;
  26. }
  27.  
  28. function loadXMLDoc(url, cb) {
  29.     var xmlhttp;
  30.     xmlhttp = new XMLHttpRequest();
  31.     xmlhttp.onreadystatechange=function() {
  32.         if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) cb(xmlhttp);
  33.     };
  34.    
  35.     xmlhttp.open("GET",url,true);
  36.     xmlhttp.send();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement