Forum Moderators: open

Message Too Old, No Replies

PHP Variable is a Java Variable

PHP Variable is a Java Variable

         

ThaSaltyDawg

7:16 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?

Birdman

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

WebmasterWorld Senior Member 10+ Year Member



How about taking all of the line breaks out of teh db data.

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

That should put on one line for you.

Birdman

ThaSaltyDawg

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

10+ Year Member



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