Using javascript in Acrobat XI. For some reason, I keep getting the following error:
invalid assignment left-hand side at 9: line 10
My code is pretty simple and looks spot on AFAICT. Please review and tell me I'm not crazy. (Or tell me I am, but you have a solution :))
function jsNetworkAccount()
{
// Get a reference to each check box
var f1 = getField("cbNetworkNotNeeded");
var f2 = getField("cbNetwork");
var f3 = getField("cbEmailAccount");
if (event.target === f1 && event.value = "On") {
f2.value = "Off";
f3.value = "Off";
return;
}
if (event.target === f2 || event.target === f3 && event.value = "On") {
f1.value = "Off"
return;
}
}
Conclusion # The "Invalid left-hand side in assignment" error occurs when we have a syntax error in our JavaScript code. The most common cause is using a single equal sign instead of double or triple equals in a conditional statement. To solve this, make sure to correct any syntax errors in your code.
The "Assignment to constant variable" error occurs when trying to reassign or redeclare a variable declared using the const keyword. When a variable is declared using const , it can't be reassigned or redeclared.
Two equal signs:
if (event.target === f1 && event.value = "On") {
// -------------------------------------^^
if (event.target === f1 && event.value === "On") {
if (event.target === f2 || event.target === f3 && event.value = "On") {
// ------------------------------------------------------------^^
if (event.target === f2 || event.target === f3 && event.value === "On") {
I used three equal signs in my code above for keeping your coding style consistent.
As vol7ron suggested, you should also add parentheses in your IF statements. This greatly improves readability in my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With