javascript - How can I get text from a user using Google Spreadsheet? -
i trying create automatic mailing system google spreadsheet. want create menu button user can press , dialog box big (paragraph-size) textbox write message in.
my problem creating right instance able pass user text input:
- i tried using
browser.inputbox("title")
, generates 1-line text box. - i tried using
spreadsheetapp.getui().prompt
method, again generates 1-line text box.
any ideas on class/method should using able user's text message?
edit here go, time using shoemodaldialog() , html code. think pretty close, not working yet. thoughts?
function showdialog() { var html = htmlservice.createhtmloutputfromfile('testhtml') .setsandboxmode(htmlservice.sandboxmode.iframe) .setwidth(600) .setheight(400); spreadsheetapp.getui() // or documentapp or formapp. .showmodaldialog(html, 'dialog title'); } function jsgettext(text) { //do string object }
<script> function mysuccessfunction(textbox) { jsgettext(textbox.value) } </script> <form method="post" > <textarea name="textbox" id="textbox" cols="60" rows="20" class="html-text-box"></textarea><br> <input type="submit" value="send" class="html-text-box" onclick="google.script.run.withsuccesshandler(mysuccessfunction).withuserobject(document.getelementbyid('textbox')); google.script.host.close()"> <input type="reset" value="cancel" class="html-text-box" onclick="google.script.host.close()"> </form>
the showdialog function looks good. don't put code onclick()
attribute. remove method="post"
form tag. don't want send post request in situation. use logger.log()
statements, , console.log()
statements, , checking execution logs server errors.
code.gs
function jsgettext(text) { logger.log('text: ' + text); logger.log('text.length: ' + text.length); (var key in text) { logger.log('key: ' + key); logger.log('value: ' + text[key]); }; var objfieldone = text['textbox']; logger.log('objfieldone: ' + objfieldone); //do string object return objfieldone; };
testhtml.html
<script> function fncgetusertxt() { var objusrinput = document.getelementbyid('idinputform'); /* (var key in objusrinput) { console.log('key: ' + key); console.log('value: ' + objusrinput[key]); }; */ google.script.run .withsuccesshandler(mysuccessfunction) .jsgettext(objusrinput); //google.script.host.close() }; function mysuccessfunction(textbox) { alert('success! : ' + textbox); }; </script> <form id='idinputform'> <textarea name="textbox" id="textbox" cols="60" rows="20" class="html-text-box"></textarea><br> <input type="submit" value="send" class="html-text-box" onmouseup='fncgetusertxt()'> <input type="reset" value="cancel" class="html-text-box" onclick="google.script.host.close()"> </form>
Comments
Post a Comment