Tuesday 15 May 2012

javascript - HTML error in Google Apps Script for EVE Online -



javascript - HTML error in Google Apps Script for EVE Online -

i working on little recreational google apps script (gas) eve online , have nail brick wall when getting server side functions talking client side ones. html:

<form id="frm1" name = "mat_add"> <input width="1000" type="text" name="mat" value="enter item here"><br /> <input type="button" value="submit" name="mat_sub" onclick= "google.script.run.withsuccesshandler(onsuccess).shortlist(this.parentnode,document.getelementbyid('spn1').innerhtml)"> </form> <span id="spn1"><table><tr><td>type name</td><td>type id</td></tr></table></span> <script> function onsuccess(output) { document.getelementbyid(output[0]).innerhtml = output[1]; }; </script>

gas:

function doget() { homecoming htmlservice.createtemplatefromfile('index').evaluate().settitle('umx web app'); }; function include(filename) { homecoming htmlservice.createhtmloutputfromfile(filename).getcontent(); }; function shortlist(form,table) { var arr = transpose(htmltoarray(table)); var item = form.mat; if ( isnan(item) ) { var url = 'https://www.fuzzwork.co.uk/api/typeid2.php?format=xml&typename=' + item.tostring(); } else { var url = 'https://api.eveonline.com/eve/typename.xml.aspx?ids=' + item.tostring(); }; var xml = urlfetchapp.fetch(url).getcontenttext(); var document = xmlservice.parse(xml); var name = document.getrootelement().getchild('result').getchild('rowset').getchild('row').getattribute('typename').getvalue(); if ( arr[0].indexof(name) == -1 && name != 'unknown type' && name != 'bad item' ) { arr[0].push(name); arr[1].push(document.getrootelement().getchild('result').getchild('rowset').getchild('row').getattribute('typeid').getvalue()); }; var str = arraytohtml(transpose(arr)); homecoming ['spn1',str] }; function arraytohtml(arr) { var = 0; var j = 0; var str = '<table>'; while ( < arr.length ) { str = str + '<tr>'; while ( j < arr[i].length ) { str = str + '<td>' + arr[i][j] + '</td>'; j += 1 }; str = str + '</tr>'; j = 0; += 1 }; str = str + '</table>'; homecoming str }; function htmltoarray(str) { var arr1 = str.replace(/<tr>/g,'</tr>').split('</tr>'); var arr2 = []; var = 1; var j = 1; var x = []; while ( < arr1.length ) { arr2.push([]); x = arr1[i].replace(/<td>/g,'</td>').split('</td>'); while ( j < x.length ) { arr2[arr2.length - 1].push(x[j]); j += 2 }; j = 1; += 2 }; homecoming arr2 }; function transpose(input) { var output = []; var = 0; var j = 0; while ( < input[0].length ) { output.push([]); while ( j < input.length ) { output[i].push(input[j][i]); j += 1 }; j = 0; += 1 }; homecoming output }; function direct(input) { homecoming input }

the problem seems on submit button because else working fine. have been looking workaround submit button point of entry can , not take more 1 variable.

the problem seems on submit button because else working fine. have been looking workaround submit button point of entry can , not take more 1 variable.

let's focus on this, , ignore irrelevant code. basic question: how multiple inputs form server-side gas function?

this illustration demonstrate communication of form object server, throwing error contains received parameters. errorhandler on client side alert received error message.

index.html <form id="frm1" name = "mat_add"> <input width="1000" type="text" name="mat" placeholder="enter item here" /><br /> <input width="1000" type="text" name="mat2" placeholder="enter quantity here" /><br /> <input type="button" value="submit" name="mat_sub" onclick="google.script.run .withsuccesshandler(onsuccess) .withfailurehandler(onfailure) .shortlist(this.parentnode)" /> </form> <script> function onsuccess(output) { document.getelementbyid(output[0]).innerhtml = output[1]; }; function onfailure(error) { alert( error.message ); } </script> code.gs function doget() { homecoming htmlservice.createtemplatefromfile('index').evaluate().settitle('umx web app'); }; function shortlist(input) { reporterr(json.stringify(input,null,2)) } function reporterr(msg) { throw new error( msg ); }

run webapp, , here's result:

the 2 named input elements, mat , mat2 communicated server function shortlist() via this.parent parameter. since button invoking this.parent in clickhandler contained in frm1 form, input elements of form included, , may referenced on server side named properties of input parameter of shortlist(). (not array elements.)

the upshot of shortlist() function can modified thusly:

function shortlist(input) { var item = input.mat; if ( isnan(item) ) { var url = 'https://www.fuzzwork.co.uk/api/typeid2.php?format=xml&typename=' + item; } else { var url = 'https://api.eveonline.com/eve/typename.xml.aspx?ids=' + item.tostring(); }; ...

javascript html google-apps-script

No comments:

Post a Comment