How to get the value of a html select form in Google App Script?
I have a HTML form in Google App Script
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="myFunction()">
<form id="myForm" >
<select id="mySelection" name="establishment" style="width:300px">
</select>
<br>
<input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
</form>
<br>
<script>
//Redundant success function:
function success(msg) {
};
//Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
function myFunction(array) {
//Loops through the array of est.
for(var i = 0 ;i < array.length; i++){
//Create an element.
var element = document.createElement("option");
//Insert Test into the element tags created above.
var textnode = document.createTextNode(array[i]);
//Append the text node to the element tags.
element.appendChild(textnode);
//appends the <option> to <select> as a child.
document.getElementById("mySelection").appendChild(element);
};
};
//Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
google.script.run
.withSuccessHandler(myFunction)
.updateEstSelect();
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
google.script.host.close();
};
</script>
</body>
</html>
JS:
function getEstValues(obj){
Logger.log(obj);
return obj;
}
The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()"
runs this getEstValues()
which then gets the form with myForm
, then iterates through the array, creates an object using name
as the key and value
as the value which then runs .getEstValues(obj);
with success handler then closes the HTML box with google.script.host.close();
The problem:
It doesn't log but when I click submit the HTML box closes.
Log:
No logs found. Use Logger API to add logs to your project.
html google-apps-script
add a comment |
I have a HTML form in Google App Script
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="myFunction()">
<form id="myForm" >
<select id="mySelection" name="establishment" style="width:300px">
</select>
<br>
<input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
</form>
<br>
<script>
//Redundant success function:
function success(msg) {
};
//Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
function myFunction(array) {
//Loops through the array of est.
for(var i = 0 ;i < array.length; i++){
//Create an element.
var element = document.createElement("option");
//Insert Test into the element tags created above.
var textnode = document.createTextNode(array[i]);
//Append the text node to the element tags.
element.appendChild(textnode);
//appends the <option> to <select> as a child.
document.getElementById("mySelection").appendChild(element);
};
};
//Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
google.script.run
.withSuccessHandler(myFunction)
.updateEstSelect();
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
google.script.host.close();
};
</script>
</body>
</html>
JS:
function getEstValues(obj){
Logger.log(obj);
return obj;
}
The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()"
runs this getEstValues()
which then gets the form with myForm
, then iterates through the array, creates an object using name
as the key and value
as the value which then runs .getEstValues(obj);
with success handler then closes the HTML box with google.script.host.close();
The problem:
It doesn't log but when I click submit the HTML box closes.
Log:
No logs found. Use Logger API to add logs to your project.
html google-apps-script
add a comment |
I have a HTML form in Google App Script
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="myFunction()">
<form id="myForm" >
<select id="mySelection" name="establishment" style="width:300px">
</select>
<br>
<input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
</form>
<br>
<script>
//Redundant success function:
function success(msg) {
};
//Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
function myFunction(array) {
//Loops through the array of est.
for(var i = 0 ;i < array.length; i++){
//Create an element.
var element = document.createElement("option");
//Insert Test into the element tags created above.
var textnode = document.createTextNode(array[i]);
//Append the text node to the element tags.
element.appendChild(textnode);
//appends the <option> to <select> as a child.
document.getElementById("mySelection").appendChild(element);
};
};
//Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
google.script.run
.withSuccessHandler(myFunction)
.updateEstSelect();
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
google.script.host.close();
};
</script>
</body>
</html>
JS:
function getEstValues(obj){
Logger.log(obj);
return obj;
}
The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()"
runs this getEstValues()
which then gets the form with myForm
, then iterates through the array, creates an object using name
as the key and value
as the value which then runs .getEstValues(obj);
with success handler then closes the HTML box with google.script.host.close();
The problem:
It doesn't log but when I click submit the HTML box closes.
Log:
No logs found. Use Logger API to add logs to your project.
html google-apps-script
I have a HTML form in Google App Script
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="myFunction()">
<form id="myForm" >
<select id="mySelection" name="establishment" style="width:300px">
</select>
<br>
<input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
</form>
<br>
<script>
//Redundant success function:
function success(msg) {
};
//Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
function myFunction(array) {
//Loops through the array of est.
for(var i = 0 ;i < array.length; i++){
//Create an element.
var element = document.createElement("option");
//Insert Test into the element tags created above.
var textnode = document.createTextNode(array[i]);
//Append the text node to the element tags.
element.appendChild(textnode);
//appends the <option> to <select> as a child.
document.getElementById("mySelection").appendChild(element);
};
};
//Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
google.script.run
.withSuccessHandler(myFunction)
.updateEstSelect();
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
google.script.host.close();
};
</script>
</body>
</html>
JS:
function getEstValues(obj){
Logger.log(obj);
return obj;
}
The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()"
runs this getEstValues()
which then gets the form with myForm
, then iterates through the array, creates an object using name
as the key and value
as the value which then runs .getEstValues(obj);
with success handler then closes the HTML box with google.script.host.close();
The problem:
It doesn't log but when I click submit the HTML box closes.
Log:
No logs found. Use Logger API to add logs to your project.
html google-apps-script
html google-apps-script
asked Nov 28 '18 at 15:26
Brandon Pillay Brandon Pillay
8218
8218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
- When you clicked the submit button, you want to see the log at
Logger.log(obj)
ofgetEstValues(obj)
.
If my understanding is correct, how about this modification?
Modification points:
- When there is
google.script.host.close()
of the bottom in the functiongetEstValues()
,google.script.host.close()'' is run before the work of
google.script.runis finished completely. Because
google.script.run`` works by the asynchronous processing. - I thought that
google.script.host.close()
of the bottom might be not required becausegoogle.script.host.close()
inwithSuccessHandler
is run.
Modified script
Please modify getEstValues()
in HTML.
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj = {};
for (var i = 0 ; i < form.length ; i++) {
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
// google.script.host.close(); // <----- Modified
}
If I misunderstand your issue, please tell me. I would like to modify it.
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522860%2fhow-to-get-the-value-of-a-html-select-form-in-google-app-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- When you clicked the submit button, you want to see the log at
Logger.log(obj)
ofgetEstValues(obj)
.
If my understanding is correct, how about this modification?
Modification points:
- When there is
google.script.host.close()
of the bottom in the functiongetEstValues()
,google.script.host.close()'' is run before the work of
google.script.runis finished completely. Because
google.script.run`` works by the asynchronous processing. - I thought that
google.script.host.close()
of the bottom might be not required becausegoogle.script.host.close()
inwithSuccessHandler
is run.
Modified script
Please modify getEstValues()
in HTML.
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj = {};
for (var i = 0 ; i < form.length ; i++) {
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
// google.script.host.close(); // <----- Modified
}
If I misunderstand your issue, please tell me. I would like to modify it.
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
add a comment |
- When you clicked the submit button, you want to see the log at
Logger.log(obj)
ofgetEstValues(obj)
.
If my understanding is correct, how about this modification?
Modification points:
- When there is
google.script.host.close()
of the bottom in the functiongetEstValues()
,google.script.host.close()'' is run before the work of
google.script.runis finished completely. Because
google.script.run`` works by the asynchronous processing. - I thought that
google.script.host.close()
of the bottom might be not required becausegoogle.script.host.close()
inwithSuccessHandler
is run.
Modified script
Please modify getEstValues()
in HTML.
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj = {};
for (var i = 0 ; i < form.length ; i++) {
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
// google.script.host.close(); // <----- Modified
}
If I misunderstand your issue, please tell me. I would like to modify it.
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
add a comment |
- When you clicked the submit button, you want to see the log at
Logger.log(obj)
ofgetEstValues(obj)
.
If my understanding is correct, how about this modification?
Modification points:
- When there is
google.script.host.close()
of the bottom in the functiongetEstValues()
,google.script.host.close()'' is run before the work of
google.script.runis finished completely. Because
google.script.run`` works by the asynchronous processing. - I thought that
google.script.host.close()
of the bottom might be not required becausegoogle.script.host.close()
inwithSuccessHandler
is run.
Modified script
Please modify getEstValues()
in HTML.
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj = {};
for (var i = 0 ; i < form.length ; i++) {
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
// google.script.host.close(); // <----- Modified
}
If I misunderstand your issue, please tell me. I would like to modify it.
- When you clicked the submit button, you want to see the log at
Logger.log(obj)
ofgetEstValues(obj)
.
If my understanding is correct, how about this modification?
Modification points:
- When there is
google.script.host.close()
of the bottom in the functiongetEstValues()
,google.script.host.close()'' is run before the work of
google.script.runis finished completely. Because
google.script.run`` works by the asynchronous processing. - I thought that
google.script.host.close()
of the bottom might be not required becausegoogle.script.host.close()
inwithSuccessHandler
is run.
Modified script
Please modify getEstValues()
in HTML.
function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj = {};
for (var i = 0 ; i < form.length ; i++) {
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
// google.script.host.close(); // <----- Modified
}
If I misunderstand your issue, please tell me. I would like to modify it.
answered Nov 28 '18 at 22:52
TanaikeTanaike
23.6k21325
23.6k21325
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
add a comment |
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
Thanks for the feedback!
– Brandon Pillay
Nov 29 '18 at 18:34
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
@Brandon Pillay Welcome. I'm glad your issue was resolved.
– Tanaike
Nov 29 '18 at 22:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522860%2fhow-to-get-the-value-of-a-html-select-form-in-google-app-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown