javascript - listbox does not pass string to google script -
when select user listbox, onchange()
event triggers function. should pass string function. code finds user's password , returns comparison. following code works fine if hard code user value, not when select listbox.
function addclients(clients){ $('#customer').empty(); $('#customer').append('<option> ---- choose user ----</option>'); (var in clients) { $('#customer').append('<option>'+clients[i]+'</option>'); $('#customer').trigger("chosen:updated"); } }
getval function:
function getval(sel){ var usrpass = google.script.run.getuserpass(sel.value); alert(usrpass); }
the function in code.gs follows
function getuserpass(userval){ var usrpass = ""; var doc = spreadsheetapp.openbyid("spreadsheet id"); var sheet = doc.getactivesheet(); var data = sheet.getrange(3, 3, sheet.getlastrow(),5).getvalues();; for(n=0;n<data.length;++n){ // iterate row row , examine data in column if(data[n][0].tostring().match(userval)==userval){ usrpass = data[n][4]}; } return usrpass; }
why return value come undefined rather password.
if hardcode username in function , run function, return value value in fifth column.
try structuring code this:
<script> function onsuccess(returnval) { alert('success! ' + returnval); }; function getval(sel){ var selectvalue = sel.value; console.log('selectvalue: ' + selectvalue); google.script.run .withsuccesshandler(onsuccess) .getuserpass(sel.value); }; </script>
you can iterate through object see in it, debugging test.
for (var propertyval in sel) { console.log('this property: ' + propertyval); console.log('this value: ' + sel[propertyval]); };
and see in object.
Comments
Post a Comment