Forum Moderators: coopster

Message Too Old, No Replies

Java Variable is a PHP Variable

Java Variable is a PHP Variable

         

ThaSaltyDawg

7:14 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



Hello all,
wasn't sure whether to pu this in the PHP or JavaScript section. So I'll put it in both.

I am trying to create a javascript variable that hold the value or a php variable. The PHP var comes from a database and holds html text. I can do all this correctly but the problem I have is that the html text is multiple lines of code. The JavaScript Variable cannot handle that because the text needs to be all on one line, and since the text is dynamic adding end line code to the JS var is not good. I am not very knowledgeable the JS syntax but I can understand anything you throw at me.

Here's what I have:

var caltext=new Array()

//Set submenu contents. Expand as needed. For each content, make sure everything exists on ONE LINE. Otherwise, there will be JS errors.

caltext[1]='<?php echo $CalendarText[1];?>'
caltext[2]='<?php echo $CalendarText[2];?>'
caltext[3]='<?php echo $CalendarText[3];?>'

This code creates text for the calendarday that I have set on an onClick event. This all work ideally. but this is the out I get to the browser:

menu[1]='<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#993300"><tr><td align=center valign=middle bgcolor="#FF9900"><strong><font color="#993300" size="4" face="Verdana, Arial, Helvetica, sans-serif">Tuesday, October 19, 2004</td></tr><tr><td><OL>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI></OL></font></strong></td></tr></table>'
menu[2]='<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#993300"><tr><td align=center valign=middle bgcolor="#FF9900"><strong><font color="#993300" size="4" face="Verdana, Arial, Helvetica, sans-serif">Wednesday, October 20, 2004</td></tr><tr><td><OL>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI></OL></font></strong></td></tr></table>'
menu[3]='<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#993300"><tr><td align=center valign=middle bgcolor="#FF9900"><strong><font color="#993300" size="4" face="Verdana, Arial, Helvetica, sans-serif">Thursday, October 21, 2004</td></tr><tr><td><OL>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI>
<LI>This is a Test</LI></OL></font></strong></td></tr></table>'

Now I have Multi-line text that cannot be in a JavaScript Variable. Is there another way I can set the variable to hold the data?

jatar_k

7:36 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not strip the newlines?

something like

caltext[1]='<?php echo str_replace("\r\n","",$CalendarText[1]);?>'

you may have to individually replace \n and \r though

ThaSaltyDawg

7:47 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



Excellent, thanks, that confirms it for, Birdman told me the same thing in the JavaScript section. Thanks to both of you.