Unterminated string constant-javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemantbasva
    New Member
    • Oct 2008
    • 12

    #1

    Unterminated string constant-javascript

    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

    Code:
    if (lblProcedureID != null)
                        {
                            lnkHold.Attributes.Add("onclick", "javascript:copyText('Procedure Id-" + lblProcedureID.Text + " Proceudre Title-" + ProcedureTitle.Text + " Procedure Description-" + ProcedureDesc.Value + "');"); 
                            //lnkHold.Attributes.Add("onclick", "javascript:copyText('" + (ProcedureDesc.Value).ToString() + "');");
    }

    javascript in aspx file

    Code:
    <script type="text/javascript" language="javascript">
                function copyText(copyDivText) 
                {
                    //var copyDivText = document.getElementById('labelclipboard').value;
                    window.clipboardData.clearData();
                    var returnVal = window.clipboardData.setData('Text', copyDivText); 
                    alert("Procedure details copied"); 
                }
        </script>
    sometimes i am also getting error
    ") expected"

    please help as its a urgent requirement

    Hemant Basvapattan
    Bangalore
    Last edited by gits; Oct 20 '08, 12:37 PM. Reason: added code tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    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.Attribu tes.Add("onclic k", "javascript:cop yText('Procedur e 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

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      In your c# you are passing these 3 items into your string
      Code:
      lblProcedureID.Text
      ProcedureTitle.Text
      ProcedureDesc.Value
      ... 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"


      Code:
      lnkHold.Attributes.Add("onclick", "javascript:copyText('Procedure Id-13 Proceudre Title-bob's palace Procedure Description-this is something');");
      now lets see the problem
      Code:
      Javascript interprets
      String1: 'Procedure Id-13 Procedure Title-bob'
      Unterminated String: s palace Procedure Description-this is something'
      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.

      Comment

      • hemantbasva
        New Member
        • Oct 2008
        • 12

        #4
        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

        Comment

        Working...