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
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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.