async function run() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
var num1 = document.getElementById("1");
var num2 = document.getElementById("2");
var num3 = document.getElementById("3");
var num4 = document.getElementById("4");
var num5 = document.getElementById("5");
var num6 = document.getElementById("6");
var num7 = document.getElementById("7");
var num8 = document.getElementById("8");
var num9 = document.getElementById("9");
function addtest(num1, num2) {
return num1 + num2;
}
console.log(num1);
await context.sync();
});
}
When I log this it returns this: HTMLButtonElement {} I want it to log its value of 1.
This is happening because you are only getting the element itself with your current JavaScript code. You should use
innerHTML
,innerText
, ortextContent
properties to get the value it holds. Please note that all of them return a string, so you should parse their values before using it.In your case, I believe
innerHTML
is what best applies. So, this is what you should be doing:Repeat this code for
num1
tonum9
and you should be good to go.The innerHTML Property
From W3Schools definition:
The example below can clarify how
.innerHTML
works a bit better:Refer to HTML DOM innerHTML Property on W3Schools for more information.