Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

vbscript response.write asp problem

Options
  • 16-05-2003 4:30pm
    #1
    Registered Users Posts: 4,222 ✭✭✭


    I'm having a problem writing out the single quote in Response.write statements in an asp

    Here's the situation and offending line of code:

    Returning a field called "Question" from an SQL Query to a recordset and trying to write out the value of returned record.

    <%
    Question = rsQuestion("Question")

    Response.write("<input type='text' name='Question' value = '" & Question & "' >")
    %>

    say the value of Question = " Foo's Question"

    what happens when the page is run is instead of getting
    Foo's Question
    i get
    Foo

    This problem only happens when writting it to a text input box but thats the control that i need.

    From looking at the HTML source its clear to see that the problem is being caused because it thinks it ' in the middle of the output string is the terminating '

    <input type='text' name='Question' style='HEIGHT: 22px; WIDTH: 378px' value = 'Foo' s question' >

    i've tried escaping and unescaping and Server.HtmlEncode but none seem to work.

    i know it works if you take it outside the asp tags and write it HTML as
    <input type="text" name="Question" style="HEIGHT: 22px; WIDTH: 378px" value ="<%= Question %>">
    but i dont want to do it like this because there are ocasions where other input text boxes are only conditionally displayed.

    any ideas?
    cheers!


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Use double rather tham single quotes, but escape them (in VBS this is done by using "" fo denote a single pritable ").

    i.e.
    <%
    Question = rsQuestion("Question")
    
    Response.write("<input type=""text"" name=""Question"" value = """ & Question & """ >")
    %>
    
    You may also use the ASCII value when printing " or ' to the buffer (i.e. Chr(34) gives you a ")


  • Closed Accounts Posts: 94 ✭✭boo-boo


    Could also try,


    Response.write("<input type='text' name='Question' value = '" & Replace(Question, "'", "'") & "' >")


  • Closed Accounts Posts: 302 ✭✭Auburn


    Originally posted by The Corinthian
    Use double rather tham single quotes, but escape them (in VBS this is done by using "" fo denote a single pritable ").

    Was going to say the same thing. These links might help:

    Link 1
    Link 2


  • Closed Accounts Posts: 94 ✭✭boo-boo


    doh ! that last post of mine looks wierd, forget to esc the html char code,

    it should be &#39;

    ie

    Replace(Question, "'", "&#39;")


  • Registered Users Posts: 4,222 ✭✭✭Scruff


    Thanks people, all suggestions work perfectly!
    :)


  • Advertisement
Advertisement