Uncaught Syntaxerror: Missing ) after argument list

Asked

Viewed 327 times

-5

Good I’m having an error in my javascript someone can help?

'<a id="showData" onclick="OpenDescriptionModal(\''+ postData[0].replace('#', '') + '\', \'' + editTitle + '\', \''+ description.replace(/"/g, '\'') +'\');" class="btn btn-success" title="View" lang="en" style="margin-top: 5px;"><i class="fa fa-eye iconInsideBtn" aria-hidden="true"></i><span>View</span></a><a style="margin-left: 1em; margin-top: 5px;" onclick="openEditModal(\''+ postData[0].replace('#', '') + '\', \'' + editTitle + '\', \''+ description.replace(/"/g, '\'') +'\');" class="btn btn-success" title="Edit" lang="en"><i class="fa fa-edit iconInsideBtn" aria-hidden="true"></i><span lang="en">Edit</span></a><a style="margin-left: 1em; margin-top: 5px;" onclick="openDeleteModal(\''+ postData[0].replace('#', '') +'\');" class="btn btn-danger" title="Delete" lang="en"><i class="fa fa-times-circle iconInsideBtn" aria-hidden="true"></i><span lang="en">Delete</span></a>' 
  • 1

    What’s in postData, editTitle and description?

  • @Marcelouchimura are the variables that have the id, title, and Description of a table.

  • 1

    I know, man; I want to know the content [facepalm]

  • @Marcelouchimura xD id is an int, the title a string coming from an input, and Description with html code, since I am using the Quill Rich text editor, and this gives me everything that is saved, in html.

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_parenthesis_after_argument_list

  • @hkotsubo as far as I can see I’m concatenating everything, but something may be happening to me.

Show 1 more comment

1 answer

0

Whole exchange

description.replace(/"/g, '\'') 

for

description.replace(/["']/g, '\\\'')

that your hide will be safe and you can sleep the sleep of Morpheus.

  • As no sample content of the variables has been provided, use this suggestion at your own risk.

  • Ahaha thank you so much! It worked! Can you explain to me why it works this way? What’s the difference?

  • The difference is I wrote description.replace(/["']/g, '\\\'') and you wrote description.replace(/"/g, '\''). Did you like my explanation, Prince of the Winged Knights? D

  • It was not necessary this part but instead of having only one ' pus as tres ', it solved my problem right away.

  • Try putting a ' in description and you will have an unpleasant surprise

Browser other questions tagged

You are not signed in. Login or sign up in order to post.