Jump to content

[SOLVED] embeding javascript


twatkins

Recommended Posts

im trying to embed the java into php here is my script

 

<?

$test = 005;

 

print "<SCRIPT LANGUAGE=\"javascript\"><!--\n";

print "function new_window()\n"

print " {\n";

print " OpenWindow=window.open(\"../test/test_image.php?pump=".$test."\", \"newwin\", \"height=300, width=400,toolbar=no,scrollbars=\"+scroll+\",menubar=no\");\n";

print " } \n";

print "//--></SCRIPT>\n";

 

?>

 

for some reason i cant figure out why when i pull the page up im my browser i get  \n"; ?> so i guess im  not ending it right

 

 

Link to comment
https://forums.phpfreaks.com/topic/60965-solved-embeding-javascript/
Share on other sites

<?
$test = 005;

print "<SCRIPT LANGUAGE=\"javascript\"><!--\n";
print "function new_window()\n"; //<---missed the ;
print " {\n";
print " OpenWindow=window.open(\"../test/test_image.php?pump=".$test."\", \"newwin\", \"height=300, width=400,toolbar=no,scrollbars=\"+scroll+\",menubar=no\");\n";
print   " } \n";
print "//--></SCRIPT>\n";

?>

option #2
<?php
$test = 005;
?>
<SCRIPT LANGUAGE="javascript">
<!--
function new_window()
OpenWindow=window.open("../test/test_image.php?pump=<?php echo $test ?>", "newwin", "height=300, width=400,toolbar=no,scrollbars=scroll,menubar=no");
}
//-->
</SCRIPT>

Unless you want to ensure that old (I'm talking ~1999 era) browsers either use or ignore your JavaScript, there's no reason to embed it in HTML comments.  All modern browsers understand JavaScript.

 

As far as your problem, MadTechie did fix it.  I recommend using single-quoted strings in PHP.  I've read that they're processed faster, since they don't interpolate embedded variables, and you don't need to escape double-quotes, either, which improves readability.

 

Finally, and this is a matter of personal preference, I suggest moving all of your JavaScript to external files.  It saves on clutter in the markup, and makes updating those scripts easier as they're in a centralized location.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.