How to add a simple calculated field to a google form?

做~自己de王妃 提交于 2021-02-16 09:57:05

问题


I'm looking for a way to add simple calculated field in a google form that will be dependent on other field's values.

The first field is a simple price field quantity * price = total_price where quantity is a numeric field entered by the user.

The second field is an end date now() + X months where X is selected by the user.

I'v taken a look at google's tutorials and found only addons which in my understanding are form wide where i'm looking for something more like a custom form field.

The best solution would be one that would calculate the fields as the user change the other input's value but a simple text in the confirmation page is also OK.

I would appreciate if anyone could point me in the right direction. Thanks.


回答1:


Scripting only can affect the creation and post-submit processing of a form. You cannot make any changes to the "live" form the user is currently looking at. What you can do is send an email to the user after the form has been submitted with a calculated summery. You could include a link to the getEditResponseUrl() if they see any errors.




回答2:


As others mentioned, Google Forms does not support calculating values in realtime. However, there are 2 Google Forms addons that let you do that (Disclaimer: I created them):

  1. For simple expressions like the ones you mentioned (quantity * price = total_price) you can use Formfacade addon - https://formfacade.com/website/google-forms-calculated-fields.html
  2. For sophisticated order forms with order total, delivery fee and order summary, you can use Neartail addon - https://formfacade.com/neartail/automatically-calculate-total-amount-in-order-form.html



回答3:


I had this problem too. I needed to build a control board using the answers incoming from a google form, The problem: when you use formulas in a column next to the sheet where the answers are submited, google inserts a new row but does not replicate the formula, so you end up copying and pasting the formula over and over again.

To solve this i used an script that copies the cell where the formula is and pastes it in all rows where the answers were.

The script is pretty simple, first you have to open the script editor in the "tools" menu, and paste the code below. You only have to "call" the sheets with a name in the code and then mark the columns where formulas are.In this case hoja1 is "BD ingresos" and hoja2 is "DB gastos"

In this case, the sheets where i have forms deploying answers are "BD ingreso" and "BD gastos", the columns where i calculate something are A, B, C, D and E in "BD ingresos" same as in "BD Gastos".

(names in spanish, sorry)

// Activar la hoja actual 
var ss = SpreadsheetApp.getActiveSpreadsheet();
// se guarda hoja1 
var hoja1 = ss.getSheetByName("BD ingreso");
var hoja2 = ss.getSheetByName("BD gastos")

function actualizar() {

// obtener ultima fila de la hoja 
var ultimaFila = hoja1.getLastRow();

rellenarColumna("A",ultimaFila,hoja1);
rellenarColumna("B",ultimaFila,hoja1);
rellenarColumna("C",ultimaFila,hoja1);
rellenarColumna("D",ultimaFila,hoja1);
rellenarColumna("E",ultimaFila,hoja1);

// obtener ultima fila de la hoja 
var ultimaFila = hoja2.getLastRow();

rellenarColumna("A",ultimaFila,hoja2);
rellenarColumna("B",ultimaFila,hoja2);
rellenarColumna("C",ultimaFila,hoja2);
rellenarColumna("D",ultimaFila,hoja2);
rellenarColumna("E",ultimaFila,hoja2);

}


function rellenarColumna(pivote, ultimaFila,hojaTrabajo)
{
 //------------------------------------------------------------- 
 //celda que contiene la información que se va a pegar. 
  var celdaCopiarFormula = hojaTrabajo.getRange(pivote+"2");
  //obtener valor de dicha celda
 var valorCeldaCopiarFormula = celdaCopiarFormula.getFormula();

 //modificar rango para que pegue la información desde la ubicacion enviada hasta la ultima fila 
var rangoTotal = pivote + "2:" + pivote + ultimaFila; 


//definir ubicacion en donde se va a pegar la informacion
var destinoPegado = hojaTrabajo.getRange(rangoTotal);
destinoPegado.setFormula(valorCeldaCopiarFormula);   
}

Then you have to create a trigger in the script editor as this image shows. Set the trigger to launch the code "actualizar" with the event "from the spreadsheet" "on form submit"



来源:https://stackoverflow.com/questions/29601211/how-to-add-a-simple-calculated-field-to-a-google-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!