Issue encountered: Uncaught SyntaxError: a closing parenthesis is missing after the argument list - JavaScript function

I created a table using arrays:

var html = [];
$.each(data,function(index,item){
   no++;
   var arr = [
    '<tr>',
       '<td>'+ no +'</td>',
       '<td>'+ item.name +'</td>',
       '<td>'+ item.address +'</td>',
       '<td>',
         '<button type="button" class="btn btn-info btn-sm" onclick="pickData('+ item.id +','+ item.name +','+ item.address +')"><i class="fas fa-plus-circle"></i></button>',
    '</td>',
    '</tr>'
    ].join('\n');
    html.push(arr);
});
$('#table').html(html);

Here is the accompanying function :

function pickData(id, name, address) {
    $("#id").val(id);
    $(".name").val(name);
    $(".address").val(address);
}

An error has been encountered:

Uncaught SyntaxError: missing ) after argument list

Can you identify where the mistake lies?

Answer №1

When writing code, it's important to double-check your variables (especially address and name) using console.log to ensure they do not contain any spaces.

For example, compare "Malibu" to "Malibu street".

If there are spaces present, make sure to include quotes around those variable values. Otherwise, your function may be invoked incorrectly like this:

pickData("yourId", "yourName", Malibu street)

However, the function itself expects to be called like this:

pickData("yourId", "yourName", "Malibu street")

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

Is it possible to pass an array by value in C programming?

I'm facing a homework problem that requires: Part A To write a C program testing whether the following data types are passed by reference or by value, and then printing the results to the terminal: int array of ints If, for example, the program c ...

Struggling to retrieve JSON data from the MercadoLibre API while consistently encountering the CORS error?

I have been attempting to access a mercadolibre API that provides JSON data I need to utilize. However, whenever I make an AJAX GET request, I keep receiving the same error: "Response to preflight request doesn't pass access control check: It does n ...

The function of JQuery .click() is successful when used on a local machine, however it is not functioning

I am facing a puzzling issue. The code in question functions perfectly on my local server, but once I uploaded it to my hostgator server, a specific function no longer executes. When I set a breakpoint in the Firefox debugger, I noticed that the function i ...

Utilize React hooks to efficiently filter multiple JSON requests

I am currently working on creating a filter system that can combine multiple filters for users to choose from, such as "big/not-big" and "heavy/not-heavy". Each filter corresponds to loading a JSON file. My goal is to merge the results of these JSON files ...

Connect button with entry field

I want to create a connection between an input element and a button, where the button triggers the input and the input remains hidden. Here is a solution that I came across: <a href="javascript:void(0)" id="files" href=""> <button id="uploadDe ...

Parse the contents of an XML file in C and output the tags

When faced with an XML file, my task is to identify, store, and print the unique tags it contains. For example, consider this XML File: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> & ...

Leveraging Google maps to find nearby stores

I recently created a store locator but hit a roadblock when I discovered that Google Maps does not allow you to iframe the entire page. Is there a workaround for this issue to display the map? Or is there an alternative method that doesn't involve ifr ...

Ways to create a group label to modify various textboxes when a click event occurs

Is it possible to change multiple textboxes with corresponding labels after a click event? Issue: The current output only displays the value of the last textbox. $(function () { $('a.edit').on('click', function (e) { e.pre ...

Creating a 2D array typedef in the C programming language

Can we create a typedef for a 2D array in C? For example: typedef char[10][10] board; The above example does not compile. Is there a workaround to achieve this or any alternate solution? ...

The reliability of next router events can sometimes be called into question as they do not always function consistently

I've been working on creating a loading screen for my Next.js project. The issue I'm facing is that sometimes the loading message stays on the screen and doesn't go away even after the page has loaded. I suspect this may be due to the state ...

REACT Issue: Unable to Select Dropdown Option with OnChange Function

I have a component that includes a select element. Upon clicking an option, the OnProductChange function returns the value. However, my e.target.value shows as [Object Object]. Yet, {console.log(product)} displays: {id: 1, name: "VAM"} Clicking on Add L ...

Commitments when using a function as an argument

While I have a good understanding of how promises function, I often struggle when it comes to passing a function as a parameter: var promise = new Promise(function(resolve, reject) { // Perform asynchronous task ec2.describeInstances(function(err, ...

Unveiled Content and Jquery: Triggering with a Double Click

Despite similar questions being asked, I wanted to present my query in a more concise manner. To better illustrate my issue, I have replicated it on jsfiddle (link provided below). The jquery event I am dealing with is: $(document).ready(function () { ...

Is there a way to access and troubleshoot the complete source code within .vue files?

I've been struggling for hours trying to understand why I'm unable to view the full source of my .vue files in the Chrome debugger. When I click on webpack://, I can see the files listed there like they are in my project tree, but when I try to o ...

Transferring a JSON-encoded string in "windows-1251" format from Python to JavaScript

What I need help with can be best exemplified with a code snippet. Before, I had the code below: content = u'<?xml version="1.0" encoding="windows-1251"?>\n' + ... # with open(file_name, 'w') as f: f.write(content.enco ...

Updating input value in React on change event

This is the code for my SearchForm.js, where the function handleKeywordsChange is responsible for managing changes in the input field for keywords. import React from 'react'; import ReactDOM from 'react-dom'; class SearchForm extends ...

JQuery / Javascript - Mouse Position Erroneously Detected

I'm currently working on developing a drawing application where users can freely draw by moving their mouse over a canvas. My goal is to create a pixel at the precise location where the user drags their mouse. However, I've encountered an issue ...

Executing numerous HTTP requests in a single Node.js HTTP request

I am attempting to make a single URL call that will fetch multiple URLs and store their JSON responses in an array, which will then be sent as the response to the end user. Here is what my code looks like: var express = require('express'); var ...

Struggling to effectively work with ArrayForm when trying to include additional form fields

I'm attempting to add a playlist in Mat-dialog that contains songs in a list using (formArray) as shown here: https://i.stack.imgur.com/diWnm.png However, I am unsure of the mistake I might be making This is how my dialogue appears: https://i.stac ...

Prefixes for logging - Consider using the not-singleton technique or another approach

I am currently developing a logging helper for Node.JS that includes several exported functions such as error and warn. For instance, I have two other scripts called test1 and test2 which make use of this "module". When initializing my logging module us ...