Javascript problem: Undefined variable

SpaceshipSpaceship
Watch

Shad

New Member
Impact
0
hey guys,

ive recently been playing around with javascript, and have had no problems, until now. it is quite a wierd problem. for example, when i define a variable:


Code:
var quoteuser_24=new Array()
quoteuser_24[0]='[something]example .......[/something]'
this would have no problem, however if i do this:

Code:
var quoteuser_24=new Array()
quoteuser_24[0]='[example]<?
?>
[/quote]'
this would have the error "undefined". im thinking it is the linebreak in the variable. Is there any solution to this so that i may use linebreaks in variables? My objective as you may have noticed is to insert the variable into a value onClick.

Help apreciated!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
It is the newline that you are doing that is causing the problem. Why do you need a newline anyway? You can re-write the code like this:

Code:
quoteuser_24[0]='[example]<?\n?>\n[/quote]'

the "\n" will give you a new line in the string.
 
0
•••
right, i wasn't sure that when inserting text into a value, \n would insert as a new line.

thanks

but theres the problem that i am getting the variable from MySQL in PHP.
and when there are line breaks in the database, how would you convert them into "\n"
i tried using $subject = str_replace("\n","<br>",$subject); however, the linebreaks still apear on the variable. not really sure what to do.

oh. i sorted the problem out, silly mistake =\

thanks for the help!
 
0
•••
you could also use the nl2br fucntion
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy — Zero Commission
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back