[thelist] dynamic data in js string

Joe Crawford jcrawford at avencom.com
Tue Oct 16 18:02:40 CDT 2001


Sam-I-Am wrote:
> I'm working with a template that gets its data from a database via a php
> templating layer. (which is all fine). But for this particular template
> I need to insert some of the data into a javascript variable assignment.
> Trouble is the data comes with a carriage return. So I start with:
>         var str = '<? getMeSomeValue() ?>';
> 
> and I get:
>         var str = '
> 32';

> which then thows an unterminated string constant error in my browser.
> Is there another way or do I need to go back to the server-side code
> (big PIA) to strip the carriage return? I can't chop the last character
> off on the client side because I can't complete the variable (string)
> assignment without causing an error.
> 
> grasping at straws,

use trim() 
http://www.php.net/manual/en/function.trim.php

hopefully that's the straw you need. :-)

	- Joe <http://artlung.com/>
-- 
...................  Joe Crawford \\ Web Design & Development
.....  mailto:jcrawford at avencom.com \\ http://www.avencom.com
.... San Diego \\ CA \\ USA \\ AVENCOM: Set Your Sites Higher




More information about the thelist mailing list