NameSilo

Javascript problem: Undefined variable

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
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
Close
you could also use the nl2br fucntion
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back