UPD: Decided
It's script.google.com question.
I have Spreadsheet with information (row - data \ column - time), every cell inside is number of free "spaces".
Example:
Date\Time | 11:00:00 | 15:00:00 | 17:00:00
01.09.2019| 10 | 15 | 30
02.09.2019| 10 | 15 | 30
03.09.2019| 10 | 15 | 30
04.09.2019| 10 | 15 | 30
After inputting in Web form date and time - program should show me how much "space" is free.
// Get information from form
<script>
function getEmptySpace(){
var presentDate = document.getElementById("dt").value;
var presentTime = document.getElementById("tm").value;
if(presentDate.length >= 10 && presentTime.length >= 8){
google.script.run.withSuccessHandler(updateEmptySpaceAdult).getSpaceAdult(presentDate,presentTime);
}
}
function updateEmptySpaceAdult(spaceAdult){
document.getElementById("anav").value = spaceAdult;
}
</script>
// My 3 functions, which sholud get cell value and return it in form
//Function 1 - getRowNum
function getRowNum(){
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");
var data = sheet.getDataRange().getValues();
var name = "19.12.2018"; //Here should be arg "presentDate" (.getSpaceAdult(presentDate,presentTime);)
for(var i = 0; i<data.length;i++){
if(data[i][0] == name){ //[0] because serch in column A
return i+1;
}
}
}
//Function 2 - getColNum
function getColNum() {
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");
var time = "17:00:00"; //Here should be arg "presentTime" (.getSpaceAdult(presentDate,presentTime);)
var range = sheet.getRange(2, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
for (var row in values) {
for (var col in values[row]) {
if (values[row][col] == time) {
return parseInt(col) + 1;
}
}
}
}
//Function 3 - getCellValue
function getCellValue(){
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");
var row = 8.0;
var col = 4.0;
var value = sheet.getRange(row, col).getValue();
}
// I think main Function is - .getSpaceAdult(presentDate,presentTime)
function getSpaceAdult(presentDate,presentTime){
*Call Function 1 - getRowNum() with arg "presentDate" and get RowNumber
*Call Function 2 - getColNum() with arg "presentTime" and get ColNumber
*Call Function 3 - getCellValue() by returns "getRowNum and getColNum" and show tabel cell value
In the end function getSpaceAdult = tabel cell value
}
arguments
function getRowNum(date, sheet){
//receives two arguments date and sheet.
//DO NOT REDCLARE date and sheet using `var`: var sheet =... or var date =
//REMOVEDvar sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");
var data = sheet.getDataRange().getValues();
//REMOVEDvar name = "19.12.2018"; //Here should be arg "presentDate" (.getSpaceAdult(presentDate,presentTime);)
for(var i = 0; i<data.length;i++){
if(data[i][0] == date){ //[0] because serch in column A
return i+1;
}
}
}
function getColNum(time, sheet) {
//receives two arguments time and sheet.
//DO NOT REDCLARE date and sheet using `var`: var sheet =... or var time =
/*Rest of your code except declarations of time/ sheet
*
*/
}
function getSpaceAdult(date, time){
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");
var row = getRowNum(date, sheet); //Get row number passing on two arguments date and sheet
var col = getColNum(time, sheet);
var value = sheet.getRange(row, col).getValue();
return value;//Added
}
getValues()
returns Object[][]
: Some/All of received values maybe date objects. Date objects cannot be compared with ==
. You may use getDisplayValues()
instead to get dates as strings.