JS code problem (Uncaught Syntaxerror: Missing ) after argument list)

Asked

Viewed 5,374 times

4

Well, I have a pop-up chatbox code, but it’s making the following mistake:

Uncaught Syntaxerror: Missing ) after argument list

Code:

 //Variáveis a editar
var imagen_chatbox_desplegable = "http://i45.servimg.com/u/f45/17/45/19/77/chat10.png";
var posicion_chatbox_desplegable = "derecha"; // ou 'izquierda'
//Fim das variáveis a editar

document.write("<div id="chatbox_ret_cont" class="chatbox_" + posicion_chatbox_desplegable + "">");
document.write("    <div onclick="(document.getElementById('chatbox_ret').style.display=='block')?my_setcookie('chatbox_ret','0',0,0):my_setcookie('chatbox_ret','1',1,0); jQuery('#chatbox_ret').toggle('normal');">");
document.write("        <span id="chatbox_ret_online">");
document.write("            <img title="Abrir e fechar o chatbox" src="" + imagen_chatbox_desplegable + "">");
document.write("        <\/span>");
document.write("        <span id="chatbox_ret_offline"><\/span>");
document.write("    <\/div>");
document.write("    <iframe src="\/chatbox" id="chatbox_ret" name="chatbox_ret" ");
document.write("       scrolling="no" frameborder="0" marginwidth="0" marginheight="1px"");
document.write("       onload="if(cb_new){cb_start();cb_new=0;}">");
document.write("    <\/iframe>");
document.write("<\/div>");

1 answer

8


You have to escape double quotes inside a double quote string, example:

"\"string dentro de uma string\""

So in your code:

document.write("<div id="chatbox_ret_cont" class="chatbox_" + posicion_chatbox_desplegable + "">");

Has to stay:

document.write("<div id=\"chatbox_ret_cont\" class=\"chatbox_" + posicion_chatbox_desplegable + "\">");

You can also trade in single quotes:

document.write('<div id="chatbox_ret_cont"></div>');

On the use of the method document.write(), it is not recommended to use it, as any other content already created in the document will be deleted. If you’re really using jQuery create this html in a string and use the append() to create the structure in the DOM.

  • Unfortunately, it remained the same and continues with the same error: Uncaught Syntaxerror: Missing ) after argument list / current code: http://pastebin.com/g1Xg5ftj

  • @Fábiomiguel dude, you copied the 6th line wrong, the correct is: document.write("<div id='chatbox_ret_cont' class='chatbox_" + posicion_chatbox_desplegable + "'>");. The 9th is also wrong: document.write(" <img title='Abrir e fechar o chatbox' src='" + imagen_chatbox_desplegable + "'>");. And the 11th too.

  • I corrected these lines, but there were more errors, these being: /+%20imagen_chatbox_desplegable%20+ Failed to load Resource: the server responded with a status of 404 (Not Found) and Uncaught Referenceerror: cb_new is not defined / current code: http://pastebin.com/FERFL9m9

  • @Fábiomiguel expensive, probably its variable cb_new does not exist at the time it is used and in the img that you tried to concatenate the value of the variable imagen_chatbox_desplegable In fact you called her name, so the image was not found. I have already explained the error and why of it, and also how to correct. I think it’s time for you to take a closer look at your code and try to solve this on your own, since these are basic syntax errors. I can’t stand here correcting every mistake you have, because that way you won’t learn to fix them.

  • You’re right. Anyway, thanks for your help ^^

Browser other questions tagged

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