What steps can be taken to troubleshoot the error message "Invalid left-hand side in assignment" in JavaScript?

This issue is really frustrating. The function is throwing this error message:

Uncaught ReferenceError: Invalid left-hand side in assignment

Can someone please help me identify where the error is occurring?

   function ok()
   {
       if (document.getElementById('titulo')='') {
           AbreSnackBar('You have to give this piece a title','red');
           exit();
       }

        var data=
           'titulo=' + document.getElementById('titulo').value +
           '&plantilla=' + document.getElementById('plantilla').value +
           '&pags=' + document.getElementById('pags').value +
           '&genero=' + document.getElementById('gen').value +
           '&comp_real=' + document.getElementById('comp_orig').value +
           '&ano=' + document.getElementById('ano').value +
           '&up_im1=' + document.getElementById('up_im1').value +
           '&up_im2=' + document.getElementById('up_im2').value +
           '&up_im3=' + document.getElementById('up_im3').value +
           '&up_ref=' + document.getElementById('up_ref').value +
           '&video=' + document.getElementById('link').value +
           '&descr=' + document.getElementById('descr').value +
           '&descr_ing=' + document.getElementById('descr_ing').value +
           '&minutos=' + document.getElementById('minutos').value +
           '&dificultad=' + document.getElementById('dif').value +
           '&up_PDF=' + document.getElementById('up_PDF').value + 
           '&up_RAR=' + document.getElementById('up_RAR').value +
           '&up_MUS=' + document.getElementById('up_MUS').value +
           '&up_SIB=' + document.getElementById('up_SIB').value +
           //'&tags=' + document.getElementById('tags').value +
           '&modo=' + document.getElementById('modo').value +
           '&id_concurso=' + document.getElementById('id_concurso').value +
           '&copias_min=' + document.getElementById('copias_min').value;

        AbreSnackBar('Wait...');
        $.ajax({
            type: "POST",       url: "acc_sube_obra.php", data: data ,
            success: function (data) 
            {
                alert(data);
                switch (data.trim())
                {
                    case '0':
                        AbreSnackBar('An error ocurred','red');
                        break;
                    default: //id
                        AbreSnackBar('Done!','green');
                        window.location.href = 'http://www.aboutscores.com/obra_subida.php?id='+ data.trim();
                }
            } 
        }); 
   }

It seems like I may be trying to assign a new value within a function result, although I can't seem to locate where that's happening.

I chose not to include the code for the AbreSnackBar function as it functions correctly and isn't relevant to this issue.

Answer №1

if (document.getElementById('titulo')='') {
                   right there ------^

Caught in the trap of the assignment operator, it seems like you meant to use == instead.

But don't forget that, as highlighted by Xufox, null != ''.

A correct version of the statement could be:

if (document.getElementById('titulo') === null) {

or

if(document.getElementById('titulo').value == '')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamically insert letters into each row as the HTML table increases

How can I display dynamically increasing alphabets in a newly generated cell on the left side of each row, based on the option selected in a dropdown list? These alphabets will serve as bullet points or serial numbers for the text boxes in each row. View ...

Change the value of an input button in an HTML tag without assigning any value to it

Currently, I am utilizing the UserWP plugin on my WordPress registration page. The button on the form currently reads "Submit Query," which I find to be subpar. I would much prefer it to say "Register" instead. Unfortunately, there doesn't seem to be ...

Obtain the total views for a particular map

Looking to optimize my use of the Google Maps JavaScript API. Any suggestions on where I can find information on tracking views and SEO for my map? Appreciate any assistance you can provide. ...

Function is never called by SetTimeout

Attempting to simulate a long running operation using a loop, like this: var x, y; x = true; y = false; while (x) { if (!y) { setTimeout(function() => { x = false; }, 1000); y = true; } } Wondering why the l ...

How to Generate Custom Expiry Tokens with Firebase Authentication

Currently utilizing Firebase 3.4.1 for my web application. The default token expiry length is sufficient to keep users logged in, but I am interested in managing the expiry manually. Ideally, I would like the token to expire at the end of each session by ...

Using window.print as a direct jQuery callback is considered an illegal invocation

Curious about the behavior when using Chrome $(selector).click(window.print) results in an 'illegal invocation' error $(selector).click(function() { window.print(); }), on the other hand, works without any issues To see a demo, visit http://js ...

Return to the initial stage of a multistep process in its simplest form following a setTimeout delay

I recently customized the stepsForm.js by Copdrops and made some modifications. Although everything works well, I'm struggling to navigate back to the initial step (first question) after submitting the form due to my limited knowledge of JavaScript. ...

How can I convert ajax response into an array?

When adding data to a database, a new ID is needed for each element. The element's ID is passed into the ajax data... $( ".silly-string" ).draggable({ containment: '#_moon_static_bg_status', stop: function(event, ui) { ...

What is the best way to create router links on the fly in Vue.js?

I am currently exploring how to achieve the following in Vue.js <table> <tr v-for="item in messages"> <td><router-link to="'/user/' + item.id">{{ item.name }}</router-link></td> </tr> < ...

Employing selenium.isElementPresent in Selenium 1 does not have the capability to identify an element that is dynamically added to the Document Object Model (

After trying out various locators, I have yet to find one that can detect an element that was added to the DOM. Below is my latest attempt at solving this issue: selenium.fireEvent("//button[2]", "click"); waitUntil(new Condition() { @Override pu ...

Modify the article category within the Ajax operation

My personal blog on GitHub Pages and Jekyll has a unique CSS styling for articles that changes randomly. Here's the code snippet: <section class="tiles"> {% for post in site.posts %} <article class="XXX" id="styleChanger"> & ...

Error encountered in MEAN stack when making an AJAX POST request: TypeError occurs when attempting to access property 'userName' of an undefined object

Currently, I am involved in the development of a MEAN stack application for my school project. The main objective is to allow users to view and submit highscores for Galaga and Dig Dug games to a MongoDB database. An issue that I am facing is: POST http ...

jQuery AJAX and PHP can be used together to verify conditions and return either

Is there a way to determine whether a PHP script returned true or false using jQuery AJAX? My current ajax call code seems to be working fine, but it always redirects to the profile page even if the login was unsuccessful... $("#signInForm").submit(func ...

Learn how to retrieve a jqGrid ajax Nested Array of Json string in C# using Newtonsoft Json

I am attempting to parse a JSON string and extract the array values within it. {"_search":true,"nd":1492064211841,"rows":30,"page":1,"sidx":"","sord":"asc","filters":"{\"groupOp\":\"OR\",\"rules\":[{\"field\":\ ...

The kendo-grid-messages are utilized across all columns

I encountered an issue while working with the following code: <kendo-grid-column field="isActive" [title]="l('Status')" filter="boolean"> <kendo-grid-messages filterIsTrue="Yes" filterIsFalse=&qu ...

JavaScript node failing to update variable value with promise value

I am facing an issue with the following code snippet- let { user } = req.body; let name = null; if (!user) { getStudent(id).then((x) => { user = x.user; name = x.name; }); } console.log(user, name); // prints undefined and null Despite us ...

"Enhancing Performance with Asynchronous Page Loading in Asp.net WebForms

I have encountered a specific question that I would like to address through discussion. In an asp.net project, there is a WebForm1.aspx with a button. When the client clicks the button, a thread is launched and immediately after that, there is a Response. ...

Reloading the table columns in a JSP page with a click of the refresh button on every row using AJAX and JavaScript

Hey there! I have a JSP page with a table where data is displayed by iterating through a list from the action class. Each row in the table has a refresh button at row level. Here is a snippet of the JSP: <script type="text/javascript"> functi ...

Using ASP.NET MVC to map FormData with an array to a model class

I am currently facing an issue with mapping a list of objects in a FormData to my ASP.NET MVC Model class at the controller. I have successfully sent the FormData over to the server-side, but I am unable to bind any value. Can someone provide guidance on h ...

In Reactjs, Axios and fetch are both commonly used for sending ongoing network requests to localhost

In order to establish a successful connection between the express backend and MongoDB database, I initially used fetch("/") from the frontend, which returned the index.html code. However, when I switched to fetch("http://localhost:9000"), I encountered a C ...