Log in

View Full Version : using javascript in admincp?


sifuhall
10-01-2009, 07:07 PM
I'm working on a new product and it is going very well.

I've added my cpnav file and am working on my admin functions and I would like to use javascript to get a confirmation before something is deleted.

I've tried printing that directly out, closing the php tags, etc, but I can't seem to get javascript from inside the admincp.

for example, I've trried the following:

if ($_REQUEST['do'] == 'equipment')
{
print "testing";
?>
<script language="javascript" type="text/javascript">
alert('123');
</script>
<?php

print_cp_header($vbphrase['lf_settings']);
print_table_break();

----- snip------



and also




if ($_REQUEST['do'] == 'equipment')
{
print "testing";

print "<script language=\"javascript\" type=\"text/javascript\">alert('123');</script>";

print_cp_header($vbphrase['lf_settings']);
print_table_break();

----- snip ------



In both cases when do == equipment I get the cp header, but no javascript is printed.

James Birkett
10-01-2009, 07:27 PM
Not sure if it'd make a difference but have you tried return?
return "<script type=\"text/javascript\">alert('confirmation')</script>";

I'd recommend running the script out of PHP tags though.. it could be that the PHP is parsing the ending javascript semi-colon as the end of the PHP string.