Regarding the quotes in a hyperlink in ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanika1507
    New Member
    • Sep 2007
    • 34

    Regarding the quotes in a hyperlink in ASP

    Hi I just want to write a hyperlink in ASP. getting many errors . can anyone please help me with this....

    Response.Write( "<font size=2 face=arial><A Class=TableLink HREF="http://cs-dev.govt.com/csscripts/login.asp?K=1234&srcserv er=cs" & "onMouseOve r=" & """" & "window.status= 'Case';return true" & """" & "onMouseOut =" & """" & "window.status= '';return true" & """" & ">Case:</A></font></td>")
    Last edited by sanika1507; Oct 26 '07, 05:49 PM. Reason: typed a small mistake
  • markrawlingson
    Recognized Expert Contributor
    • Aug 2007
    • 346

    #2
    You're breaking the string. The quote at the beginning of the http://.... is being interpretted as an END quote, and the link http://... is being looked at as a variable or an object by ASP.

    There are several ways to get around this.

    1) Use single quotes.
    2) Use 3 double quotes, not 1.
    3) Use Chr( 34 ), which is a quote, but not interpretted by ASP as an ending to your string. I use Chr( 34 ) in my code, I don't like the other two methods very much.

    [CODE=ASP]
    Response.Write "<font size=2 face=arial><A Class=TableLink HREF=" & Chr( 34 ) & "http://cs-dev.govt.com/csscripts/login.asp?K=123 4&srcserver=c s" & Chr( 34 ) & " onMouseOver=" & Chr( 34 ) & "window.status= 'Case';return true" & Chr( 34 ) & " onMouseOut=" & Chr( 34 ) & "window.status= '';return true" & Chr( 34 ) & ">Case:</A></font></td>"
    [/CODE]

    Sincerely,
    Mark

    Comment

    • sanika1507
      New Member
      • Sep 2007
      • 34

      #3
      Originally posted by markrawlingson
      You're breaking the string. The quote at the beginning of the http://.... is being interpretted as an END quote, and the link http://... is being looked at as a variable or an object by ASP.

      There are several ways to get around this.

      1) Use single quotes.
      2) Use 3 double quotes, not 1.
      3) Use Chr( 34 ), which is a quote, but not interpretted by ASP as an ending to your string. I use Chr( 34 ) in my code, I don't like the other two methods very much.

      [CODE=ASP]
      Response.Write "<font size=2 face=arial><A Class=TableLink HREF=" & Chr( 34 ) & "http://cs-dev.govt.com/csscripts/login.asp?K=123 4&srcserver=c s" & Chr( 34 ) & " onMouseOver=" & Chr( 34 ) & "window.status= 'Case';return true" & Chr( 34 ) & " onMouseOut=" & Chr( 34 ) & "window.status= '';return true" & Chr( 34 ) & ">Case:</A></font></td>"
      [/CODE]

      Sincerely,
      Mark
      i m gettin the same out put.i m not gettin the hyperlink !!!!!!!!!

      Comment

      • sanika1507
        New Member
        • Sep 2007
        • 34

        #4
        Thanks brother i m gettin it now!!!!!!!!!!

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          For the problems you illustrated I agree with Mark. It is easier to write chr(34) than try to remember how many quote marks you have used and whether you are within a string at any given point.

          Another option is to put the link outside of the ASP delimiters:
          [code=asp]'code here %>
          <font size=2 face=arial><A Class=TableLink HREF="http://cs-dev.govt.com/csscripts/login.asp?K=123 4&srcserver=c s" onMouseOver="wi ndow.status='Ca se';return true" onMouseOut="win dow.status='';r eturn true">Case:</A></font></td>
          <%
          'continue code[/code]Of course it is up to you to decide when to switch between ASP and HTML code, but I tend to switch to HTML when I need to write a lot of quote marks.

          Jared

          Comment

          • sanika1507
            New Member
            • Sep 2007
            • 34

            #6
            Originally posted by jhardman
            For the problems you illustrated I agree with Mark. It is easier to write chr(34) than try to remember how many quote marks you have used and whether you are within a string at any given point.

            Another option is to put the link outside of the ASP delimiters:
            [code=asp]'code here %>
            <font size=2 face=arial><A Class=TableLink HREF="http://cs-dev.govt.com/csscripts/login.asp?K=123 4&srcserver=c s" onMouseOver="wi ndow.status='Ca se';return true" onMouseOut="win dow.status='';r eturn true">Case:</A></font></td>
            <%
            'continue code[/code]Of course it is up to you to decide when to switch between ASP and HTML code, but I tend to switch to HTML when I need to write a lot of quote marks.

            Jared

            Actually i used it like this now

            Response.Write( "<td><A Class=TableLink HREF = 'http://cs-dev.govt.com/csscripts/login.asp?K="& SecEncode(Id) &" &srcserver=C S' > " &SecEncode(I d) &" </a> </td>")
            .........
            it works . but sme how i want this also
            onMouseOver="wi ndow.status='Ca se';return true" onMouseOut="win dow.status='';r eturn true">
            but i get an error in the applicaton Unterminated string constant
            i knw this means there is as string which is not closed . but i have closed all properly.......

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              Originally posted by sanika1507
              ... but i have closed all properly.......
              That's what I'm talking about. There are so many quote marks it is nearly impossible to keep them straight on the first go, and there is still considerable difficulty cleaning it up. I would recommend you go outside the ASP delimiters:
              [code=asp]<td><A Class="TableLin k" HREF="http://cs-dev.govt.com/csscripts/login.asp?K=<%= SecEncode(Id)%> &srcserver=C S"
              onMouseOver="wi ndow.status='Ca se';return true" onMouseOut="win dow.status='';r eturn true"><%=SecEnc ode(Id)%></a></td>[/code]

              Comment

              Working...