jeff5656 Posted February 24, 2013 Share Posted February 24, 2013 (edited) Inside a <script type="text/javascript"> I have a function. Insuide that function I am echoing out variables using php code. while ($reqarray=mysql_fetch_assoc($rrr)){ ?>errors += checkText(formname, '<?php echo $reqarray['var_name'];?>', '<?php echo $progarray[$progname];?>');<?php } however, the script does not work because there is no line break after each "errors += checkText..." line. Apparently the script won't work unless everything is on it's own separate line (even though it ends with a semi-colon;). How do I echo out a line break inside the while loop to put each one on a separate line? If I echo a <br/> it doesn't work(it just puts the text <br/> there. Edited February 24, 2013 by jeff5656 Quote Link to comment https://forums.phpfreaks.com/topic/274891-using-php-to-insert-a-line-break-inside-javascript/ Share on other sites More sharing options...
kicken Posted February 24, 2013 Share Posted February 24, 2013 Just put that JS code on it's own line. Anything outside of PHP tags is used as it is pretty much: while ($reqarray=mysql_fetch_assoc($rrr)){ ?> errors += checkText(formname, '<?php echo $reqarray['var_name'];?>', '<?php echo $progarray[$progname];?>'); <?php } You should also use json_encode() for echoing out your PHP variables, that why the are properly escaped for JS output: while ($reqarray=mysql_fetch_assoc($rrr)){ ?> errors += checkText(formname, <?php echo json_encode($reqarray['var_name']); ?>, <?php echo json_encode($progarray[$progname]);?> ); <?php } Quote Link to comment https://forums.phpfreaks.com/topic/274891-using-php-to-insert-a-line-break-inside-javascript/#findComment-1414685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.