At end of a successful php if statement call javascript function

Can this be done guy?

Below I have my php


if($_FILES['logo']['name']=="") {
copy("$src","$fname2");
$q24=mysql_query("update category set category_Name='$name', category_metaTitle='$meta', category_Image='$fname2', category_Description='$desc1', category_Active='$active' where cat_Id=$sr") or die (mysql_error());
$flag=1;
$conf="Data Updated Successfully 1";
} else {
copy("$src","imgdata/category/$fname");
$q24=mysql_query("update category set category_Name='$name', category_metaTitle='$meta', category_Image='imgdata/category/$fname', category_Description='$desc1' where cat_Id=$sr") or die (mysql_error());
$flag=1;
$conf="Data Updated Successfully 2";
}

At the bottom of each I have a successful call, ($conf=“Data Updated Successfully 1”) but what I would like to do is call a javascript function instead of the script being called using a button as below.


<input type="button" onclick="javascript:cover();" value="fade now" />

Can this be done

$conf='<input type="button" onclick="javascript:cover();" value="fade now" />';
echo $conf;

This code will generate your required button after successful completion of code.

Hi Susen,

I cant test it at the moment, but will that code produce a button instead of what I want to do which is to call the function that that button would call when clicked.

So basically, at the end of the script where I would call $conf=“Data Updated Successfully 1”, I wont it to call the javascript function instead of calling the javascript function by clicking the button.

Thanks for getting back to me.

This is the javascript Im talking about

<script type=“text/javascript”>
var vis=1;
function cover()
{
var cover=document.getElementById(‘cover’);
if(vis)
{
vis=0;
cover.style.display=‘block’;
}
else
{
vis=1;
cover.style.display=‘none’;
}
}
</script>

And also what that does.

<div id=“cover”>
<div id=“warning”>
<p align=“center”>
<input type=“button” onclick=“javascript:cover();” value=“I LIKE THIS PAGE” /> <input type=“button” onclick=“javascript:location.href=(‘http://www.#.com/’);” value=“I WANT TO SEE SOMETHING DIFFERENT” />
</p>
</div>
</div>

I think you already define the JavaScript functions in a separate js file. If so then you only need to call the function to run it. In such case use code,

$conf='<script type="text/javascript">FunctionToRun();</script>';
echo $conf; 

But if you want to load the function with the page load then you have to define the function also.
The function cover() actually switch the visibility of the division ID ‘cover’ (and all of its child elements) from visible to non-visible state and vice versa.

Hi Susen,

Your code looks fine to me, but cant seem to get the jscript function to run.

I’m using below


echo '<script type="text/javascript">cover();</script>';

Which is referencing this function.


<script type="text/javascript">
alert ("0");
var vis=1;
function cover()
alert ("1");
{
var cover=document.getElementById('cover');
if(vis)
{
vis=0;
cover.style.display='block';
alert ("2");
}
else
{
vis=1;
cover.style.display='none';
alert ("3");
}
}
</script>

Which turns on this div to create a greyed out cover that sits over the page.


<div id="cover">
<div id="warning">
<p align="center">
<input type="button" onClick="javascript:location.href=('http://www.accendsandbox.co.uk/adminSallam/admin_categories.php');" value="Return to admin" />
</p>
</div>
</div>

Cheers