[php] app

Viewer

  1. <?php 
  2. $var = 'function getBathValue() {
  3.     var uiBathrooms = document.getElementByName("uiBathrooms");
  4.     for (var i in uiBathrooms) {
  5.       if(uiBathrooms[i].checked) {
  6.           return parseInt(i)+1;
  7.       }
  8.     }
  9.     return -1; // Invalid Value
  10.   }
  11.   
  12.   function getBHKValue() {
  13.     var uiBHK = document.getElementsByName("uiBHK");
  14.     for(var i in uiBHK) {
  15.       if(uiBHK[i].checked) {
  16.           return parseInt(i)+1;
  17.       }
  18.     }
  19.     return -1; // Invalid Value
  20.   }
  21.   
  22.   function onClickedEstimatePrice() {
  23.     console.log("Estimate price button clicked");
  24.     var sqft = document.getElementById("uiSqft");
  25.     var bhk = getBHKValue();
  26.     var bathrooms = getBathValue();
  27.     var location = document.getElementById("uiLocations");
  28.     var estPrice = document.getElementById("uiEstimatedPrice");
  29.   
  30.     var url = "http://127.0.0.1:5000/predict_home_price"; //Use this if you are NOT using nginx which is first 7 tutorials
  31.     //var url = "/api/predict_home_price"; // Use this if  you are using nginx. i.e tutorial 8 and onwards
  32.   
  33.     $.post(url, {
  34.         total_sqft: parseFloat(sqft.value),
  35.         bhk: bhk,
  36.         bath: bathrooms,
  37.         location: location.value
  38.     },function(data, status) {
  39.         console.log(data.estimated_price);
  40.         estPrice.innerHTML = "<h2>" + data.estimated_price.toString() + " Lakh</h2>";
  41.         console.log(status);
  42.     });
  43.   }
  44.   
  45.   function onPageLoad() {
  46.     console.log( "document loaded" );
  47.     var url = "http://127.0.0.1:5000/get_location_names"; // Use this if you are NOT using nginx which is first 7 tutorials
  48.     //var url = "/api/get_location_names"; // Use this if  you are using nginx. i.e tutorial 8 and onwards
  49.     $.get(url,function(data, status) {
  50.         console.log("got response for get_location_names request");
  51.         if(data) {
  52.             var locations = data.locations;
  53.             var uiLocations = document.getElementById("uiLocations");
  54.             $(\'#uiLocations\').empty();
  55.             for(var i in locations) {
  56.                 var opt = new Option(locations[i]);
  57.                 $(\'#uiLocations\').append(opt);
  58.             }
  59.         }
  60.     });
  61.   }
  62.   
  63.   window.onload = onPageLoad;';

Editor

You can edit this paste and save as new:


File Description
  • app
  • Paste Code
  • 24 Mar-2023
  • 2.18 Kb
You can Share it: