homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript and PHP help
andrewsmd

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3672298 posted 5:23 pm on Jun 11, 2008 (gmt 0)

I need to display multiple lines with JavaScript and PHP here is my code.
Header("content-type: application/x-javascript");

//displays an alert box with a php varible $msg passed into it
function echoAlert($msg){

echo "alert('$msg')";

}//echoAlert

$var = ("File Written to Sybase01\\\insurance$\\\MSBCBS\\\Send Log\\\Sending\\nContents:");

//$lines is an array of a multiple line text file
foreach($lines as $i){

//function to be used later
//writeLog($username, $i);
$var .=("\\n {$i}");
}//foreach

echoAlert($var);

This code is executed by another javascript file when the user clicks a button. The problem is my alert box says error missing ")" after argument list. If I manually store multiple lines of var i.e.
$var .= ("\\n {$text1}");
$var .= ("\\n {$text2}");
The alert box works fine.
As I am not a Javascript person, I believe it either has something to do with the way the variable is stored in the array or my escape characters. Any suggestions, thanks in advance.

 

korkus2000

WebmasterWorld Senior Member korkus2000 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3672298 posted 2:27 pm on Jun 12, 2008 (gmt 0)

It could possibly be what is in the array. Try looking at whats in the array and see if it has any characters that need to be escaped. Other than that I am not sure why it is working one way and not the other.

StupidScript

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3672298 posted 9:50 pm on Jun 13, 2008 (gmt 0)

I'm not a big fan of trying to execute a client-side action with a server-side language, so I've broken your script up into server- and client-side sections:

<script type="text/javascript">
function echoAlert(msg){
alert(msg);
}
</script>
<?php
$var = ("File Written to Sybase01\\\insurance$\\\MSBCBS\\\Send Log\\\Sending\\nContents:");
foreach($lines as $i){
$var .=("\\n {$i}");
}
?>
<script type="text/javascript">
echoAlert('<?php echo $var?>');
</script>

This works fine. Your original code did nothing except print out "echo ('File written.." for me.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved