Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript error "missing ) after argument list" when trying to display user text

Posted on 2011-03-09
5
Medium Priority
?
604 Views
Last Modified: 2012-05-11
I'm using ckEditor to getuser text and store it thereafter in Sql Server 2005 database.
In some cases (identified as paste from word) , when trying to display the user input in a jquery dialog, the dialog is not opening, and firebug shows this error:  "missing ) after argument list".
An error example is: "missing ) after argument list; Apple-style-span" style="border-collap...ans: 2; text-indent: 0px; text-transfo"
I have attached the original user input and the code that retrieves the data and display it to enduser.
Please help me with a solution that could "clear" extra html tags.
 Thanks!
user input:
Hello,
This is the first sample text.
This is the second sample text.

what is stored in database:
<p> &nbsp;</p><div style="font-family: Arial,Verdana,sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255);"> <p>  <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">Hello,,</span></p> <p>  <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">This is the first sample text..</span></p> <p>  <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">This is the second sample text..</span></p> <p>  <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">

code to store user input:
string currentNote = CaseTextArea.Text;
HttpUtility.HtmlEncode(currentNote);
--update procedure--

code to get user input and display it in jquery dialog:
 string comments = "";
                cmd.CommandText = "dbo.prc_csGetCaseNotes";
                cmd.Parameters.AddWithValue("@CaseInstanceId", caseInstanceId);
                cmd.CommandType = CommandType.StoredProcedure;
                sqlConn.Open();
                SqlDataReader rdr1 = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                rdr1.Read();
                if (rdr1.HasRows)
                {
                    comments = rdr1["NoteText"].ToString();
                    comments = HttpUtility.HtmlDecode(comments);
                }
                sqlConn.Close(); 
                HttpUtility.HtmlEncode(comments);

System.Text.StringBuilder sbScript = new System.Text.StringBuilder();
                sbScript.Append(@"$(function() {");
                sbScript.Append(@"$('#divShowDetails').append('<br/><b>Comentarii:</b><br/>" + comments + "');");
                sbScript.Append(@"$('#divShowDetails').css('display','block');");
                sbScript.Append(@"$('#divShowDetails').dialog('option','width','750');");
                sbScript.Append(@"$('#divShowDetails').dialog('option','height','500');");
                sbScript.Append(@"$('#divShowDetails').dialog('open');});");                
                if (!Page.ClientScript.IsStartupScriptRegistered("scriptShowOffersComments"))
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptShowOffersComments", sbScript.ToString(), true);

Open in new window

0
Comment
Question by:danielivanov2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
dxdinh earned 1600 total points
ID: 35092835
you have single quote "'" within your comments field

'Times New Roman';

so I would try to escape character

from
                sbScript.Append(@"$('#divShowDetails').append('<br/><b>Comentarii:</b><br/>" + comments + "');");
 ---
to                sbScript.Append(@"$('#divShowDetails').append('<br/><b>Comentarii:</b><br/>" + comments.Replace("'", @"\'") + "');");
 
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 35093508

//Try something like this for better readability:

sbScript.Append(@"
  $(function() {
    $('#divShowDetails').append('<br/><b>Comentarii:</b><br/>" + comments + "');
    $('#divShowDetails').css('display','block');
    $('#divShowDetails').dialog('option','width','750');
    $('#divShowDetails').dialog('option','height','500');
    $('#divShowDetails').dialog('open');
  });
");

0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 35093613

Of course you will need EncodeJsString( comments ) as well.

public static string EncodeJsString(string s) 
{ 
StringBuilder sb = new StringBuilder(); 
foreach (char c in s) 
{ 
switch (c) 
{ 
case '\'': 
sb.Append("\\\'"); 
break; 
case '\"': 
sb.Append("\\\""); 
break; 
case '\\': 
sb.Append("\\\\"); 
break; 
case '\b': 
sb.Append("\\b"); 
break; 
case '\f': 
sb.Append("\\f"); 
break; 
case '\n': 
sb.Append("\\n"); 
break; 
case '\r': 
sb.Append("\\r"); 
break; 
case '\t': 
sb.Append("\\t"); 
break; 
default: 
int i = (int)c; 
if (i < 32 || i > 127) 
{ 
sb.AppendFormat("\\u{0:X04}", i); 
} 
else 
{ 
sb.Append(c); 
} 
break; 
} 
} 

return sb.ToString(); 
}

Open in new window


[ref]
0
 

Author Comment

by:danielivanov2
ID: 35096462
I have put in ckeditor the string detalied in first post (what was stored in database), modified the script to encode js string:
 string currentNote = CaseTextArea.Text;
            EncodeJsString(currentNote);
            HttpUtility.HtmlEncode(currentNote);
but the result is aproximately the same: cannot open dialog, javascript error:

missing ) after argument list
[Break On This Error] na,sans-serif; font-size: 12px; color:...; font-style: normal; font-variant: no
0
 

Author Closing Comment

by:danielivanov2
ID: 35106193
It worked by removing single quote, that was the problem
thanks!
0

Featured Post

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question