I'd like to create my first Google Docs Script to generate an amount but it seems not working well like this :
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Start', 'showSidebar')
.addToUi();
}
function onInstall(e) {
onOpen(e);
}
function showSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('Sidebar').setTitle('Calcul tarification Icecom');
DocumentApp.getUi().showSidebar(ui);
}
function calculPrice(compagnyType, hours) {
// here I'm not able to get "compagnyType" and "hours"
var pricePerDay = 300;
switch (compagnyType) {
case 'PME':
pricePerDay = 350;
break;
case 'ESI':
pricePerDay = 400;
break;
case 'GE' :
pricePerDay = 450;
break;
}
return pricePerDay * hours;
}
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<style></style>
<div class="sidebar branding-below">
<form>
<div class="block col-contain">
<div class="col-one">
<label for="compagnyType">Type de l'entreprise</label>
<select id="compagnyType" name="compagnyType">
<option>TPE</option>
<option>PME</option>
<option>ESI</option>
<option>GE</option>
</select>
</div>
</div>
<div class="block form-group">
<label for="hours"><b>Nombre d'heures</b></label>
<input type="text" id="hours" name="hours"/>
</div>
<div class="block" id="button-bar">
<button class="blue" id="calculPrice">Calculer</button>
</div>
</form>
<div id="result"></div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
$('#calculPrice').click(calculPrice);
});
function calculPrice() {
var compagnyType = $('select[name=compagnyType]').val();
var hours = $('input[name=hours]').val();
var result = google.script.run.calculPrice(compagnyType, hours);
$('#result').text(result);
}
</script>