Reputation: 573
I want to display googlespreadheet cell "B2"and "C2" value in my HTML submit form input box, "B2" in input box 'details' and "C2" value in input box 'quantity'.
Mentioned below is my HTML code :-
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<br>
<form>
Details:<br>
<input type="text" name="details">
<br> Quantity:
<br>
<input type="text" name="quantity">
<br><br>
<input type="button" value="Submit" onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
</html>
Thankyou in advance for your help.
Upvotes: 1
Views: 3881
Reputation: 3355
Try this...
HTML:
<head>
<base target="_top">
</head>
<br>
<form>
Details:<br>
<input type="text" name="details" id="details">
<br> Quantity:
<br>
<input type="text" name="quantity" id="quantity">
<br><br>
<input type="button" value="Submit" onclick="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd(this.parentNode)" />
</form>
<script>
window.addEventListener('load', populate());
function populate(){
google.script.run.withSuccessHandler(displayValue).fetchValues();
}
function displayValue(data){
document.getElementById("details").value=data[0][0];
document.getElementById("quantity").value=data[0][1];
}
</script>
</html>
Script:
function fetchValues(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); //Enter your sheet Name
var data = sheet.getRange(2,2,1,2).getValues();
return data;
}
Upvotes: 1