Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. var url = 'http://api.fixer.io/latest?base=CAD'
  2. var val="";
  3.  
  4.  
  5.  
  6. $(document).one('pagecreate',function(){ //page create function
  7.  
  8. function getData(){
  9.  
  10.  
  11. /*$.getJSON(json).done(function (data) { //pass in data as a parameter
  12.  
  13. $.each(data, function(index, json) { //this passes in data as a parameter and for each data, we call the function
  14. console.log(json); //this is the json object printed out for each key and value
  15. val = json.rates;
  16. var data=JSON.stringify(json, null, "\t");
  17. $("#testpara").text(data);
  18.  
  19. });
  20. }); */
  21.  
  22. $.getJSON(url).done( function(json){
  23. val = json.rates;
  24. console.log(val);
  25. var data=JSON.stringify(val, null, "\t");
  26. // $("#testpara").text(data);
  27. });
  28.  
  29. }
  30.  
  31. getData(); //call the function
  32.  
  33. function changeexchangeTextBox() {
  34.  
  35. $("#exchangetextbox").change(function() {
  36. var cad = $("#exchangetextbox").val();
  37.  
  38. var usd = cad*val["USD"];
  39.  
  40.  
  41. $("#usd").html("USD: $" +usd.toFixed(2));
  42.  
  43. })
  44. var collapsibleHeader = $("<h3></h3>").text("Other Rates"); //print the title in the header
  45.  
  46.  
  47. collapsibleBody = "<p>";
  48.  
  49.  
  50. $.each(val, function(key, value) {
  51. //display the key and value pair
  52. if (key !== "USD") {
  53. collapsibleBody += " " + key + ':' + (value*cad).toFixed(2) + '<br>';
  54. }//end if
  55.  
  56. collapsibleBody += "</p>"
  57.  
  58. });
  59.  
  60. //print the answer in the collapsible body
  61. var div = $('<div data-role="collapsible"></div>').append(collapsibleHeader).append(collapsibleBody)
  62. $("#displayrates").append($(div).collapsible()); //this is used to append and initialize the collapsible widget, similar to listview refresh method
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. changeexchangeTextBox();
  70.  
  71.  
  72.  
  73.  
  74.  
  75. });//ends document on page create
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement