By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

Unterminated string constant-javascript

hemantbasva
P: 12
i have written a the following javascript code to copy data onto clipboard but i am getting error
Unterminated string constant

code in cs file

Expand|Select|Wrap|Line Numbers
  1. if (lblProcedureID != null)
  2.                     {
  3.                         lnkHold.Attributes.Add("onclick", "javascript:copyText('Procedure Id-" + lblProcedureID.Text + " Proceudre Title-" + ProcedureTitle.Text + " Procedure Description-" + ProcedureDesc.Value + "');"); 
  4.                         //lnkHold.Attributes.Add("onclick", "javascript:copyText('" + (ProcedureDesc.Value).ToString() + "');");
}

javascript in aspx file

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.             function copyText(copyDivText) 
  3.             {
  4.                 //var copyDivText = document.getElementById('labelclipboard').value;
  5.                 window.clipboardData.clearData();
  6.                 var returnVal = window.clipboardData.setData('Text', copyDivText); 
  7.                 alert("Procedure details copied"); 
  8.             }
  9.     </script>
sometimes i am also getting error
") expected"

please help as its a urgent requirement

Hemant Basvapattan
Bangalore
Oct 20 '08 #1
Share this Question
Share on Google+
3 Replies


RamananKalirajan
100+
P: 607
Sorry I dont know much things about CS but ur code is working well in HTML (that I tried). The problem may be in ur code is in this line

[HTML]lnkHold.Attributes.Add("onclick", "javascript:copyText('Procedure Id-" + lblProcedureID.Text + [/HTML]

Before the Procedure Id- there was a single quotes but it was not ended. Just check it out

Regards
Ramanan Kalirajan
Oct 20 '08 #2

iam_clint
Expert 100+
P: 1,208
In your c# you are passing these 3 items into your string
Expand|Select|Wrap|Line Numbers
  1. lblProcedureID.Text
  2. ProcedureTitle.Text
  3. ProcedureDesc.Value
  4.  
... as far as I can tell you aren't validating these items so let me put this in context..


lets say lblProcedureID = 13, ProcedureTitle = "bob's palace", ProecureDesc = "this is something"


Expand|Select|Wrap|Line Numbers
  1. lnkHold.Attributes.Add("onclick", "javascript:copyText('Procedure Id-13 Proceudre Title-bob's palace Procedure Description-this is something');");  
  2.  
now lets see the problem
Expand|Select|Wrap|Line Numbers
  1. Javascript interprets
  2. String1: 'Procedure Id-13 Procedure Title-bob'
  3. Unterminated String: s palace Procedure Description-this is something'
  4.  
as you can see the string starts and ends before everything is executed.


This is how I imagine you are coming up with this error.
Oct 20 '08 #3

hemantbasva
P: 12
yes the problem is with the procedure description only.either due to length or due to special character. i will trace it out
Thanks everyone for help
Oct 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.