Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript error : invalid assignment left-hand side

Tags:

javascript

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;

    }    
}
like image 955
Scott Holtzman Avatar asked Sep 25 '13 21:09

Scott Holtzman


People also ask

How do I fix invalid left-hand side in assignment?

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.

What is assignment error in js?

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.


1 Answers

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.

like image 60
ComFreek Avatar answered Oct 13 '22 00:10

ComFreek