Handling 'multi-line' string variables


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Handling 'multi-line' string variables

  1. #1
    neilm Guest

    Handling 'multi-line' string variables


    My application needs to read a field from a database that contains a multi-line
    piece of text (actually a piece of html code). I want to store this string
    in a client side javascript variable (want to be able to assign it to a text
    box in a form). Code looks like this

    <% dim sz
    ...
    sz = rs("tmltext")
    ...
    %>

    <SCRIPT LANGUAGE="javascript">
    var sz = "<% = sz %>"
    ...
    </SCRIPT>

    The expansion of <% = sz %> (obviously) causes a scripting error as it inserts
    lines of html into the script. How do I get around this problem? Thanks.

  2. #2
    cripper Guest

    Re: Handling 'multi-line' string variables


    It would occur to me that quite possibly you are attempting to use a
    server side call from client side script
    e.g.(
    <SCRIPT LANGUAGE="javascript">
    var sz = "<% = sz %>"
    ...
    </SCRIPT>
    )

    Thats a no,no.

    What you might try is generating the client side script in the .asp server
    side code. (e.g. Response.write ("<SCRIPT LANGUAGE=""javascript"">") & chr(10)
    & chr(13)
    Response.write ("var sz =") & sz
    Response.write </SCRIPT>

    Or something along those lines this reply is a little rushed. But the concept
    is generate the entire script tags in the .asp code and utilize the server
    side variable there.


  3. #3
    Matthew Solnit Guest

    Re: Handling 'multi-line' string variables

    "cripper" <s_crappa@hotmail.com> wrote in message
    news:3be1fd6b$1@147.208.176.211...
    >
    > var sz = "<% = sz %>"
    >
    > Thats a no,no.


    Why?

    -- Matthew Solnit



  4. #4
    candy Guest

    Re: Handling 'multi-line' string variables


    Hi, if anyone knew the answer to the below I would also be interested in the
    answer thanks, Candy

    "Matthew Solnit" <msolnit@y@hoo.c0m> wrote:
    >"cripper" <s_crappa@hotmail.com> wrote in message
    >news:3be1fd6b$1@147.208.176.211...
    >>
    >> var sz = "<% = sz %>"
    >>
    >> Thats a no,no.

    >
    >Why?
    >
    >-- Matthew Solnit
    >
    >



  5. #5
    Russell Jones Guest

    Re: Handling 'multi-line' string variables

    The construction is a perfectly acceptable way to transfer values from the
    server to a client-side script.

    There's nothing wrong with that code as long as you understand what it does.
    In this case, it creates a line of client-side script that defines a string
    variable. However, you also have to understand that the value of the
    client-side sz variable is the value of the server-side sz variable _at the
    time the page was created_, and that changing the client-side variable _does
    not_ affect the value of the server-side variable. Finally, you need to
    understand that the code between the <% %> tags only runs on the server. The
    code doesn't dynamically connect to the server and retrieve a value--the
    client-side sz variable gets its value because the server resolves the <%=
    sz%> code when it creates the page.

    Russell Jones
    Sr. Web Development Editor,
    DevX.com

    "candy" <candy@apsc.ubc.ca> wrote in message
    news:3be81d50@147.208.176.211...
    >
    > Hi, if anyone knew the answer to the below I would also be interested in

    the
    > answer thanks, Candy
    >
    > "Matthew Solnit" <msolnit@y@hoo.c0m> wrote:
    > >"cripper" <s_crappa@hotmail.com> wrote in message
    > >news:3be1fd6b$1@147.208.176.211...
    > >>
    > >> var sz = "<% = sz %>"
    > >>
    > >> Thats a no,no.

    > >
    > >Why?
    > >
    > >-- Matthew Solnit
    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center