...

View Full Version : How to Call javascript function from php code?



faraz aleem
02-02-2007, 07:47 PM
Hi,
I wana call javascript function frm php code in my else block,i tried this way
<?PHP
if()
{
SOME CODE
}
else
{
echo "<script language=javascript>divclose()</script>";//divclose() function just

make this div style to none
}
?>


bt it didnt work.Help is required how can i call javascript function from php code,and i

dont wana call this javascript function on any event like onClick() or onMouseOver().I want

this fuction to be called when else block will run.
Telling the bigger picture of my problem,my form is appearing in a div and i want to close

this div(mydiv.style.display = "none") in javascript function,problem i m facing is i m

unable to call a javascript function.Can any tell me an alternate way of how can i make my

div-display-style="none" using php code.

mlseim
02-02-2007, 09:17 PM
I made this little test and it works fine.

Are you sure you have a Javascript function on your page or
in an external .js file? Maybe there's nothing to call. Since we
can't see the rest of your script ...

Here's my test:


<?php

echo "
<html>
<head>
<SCRIPT LANGUAGE='javascript'>
function DivClos() {
alert (\"this is a test\");
}
</SCRIPT>
</head>
<body>
";

$x=1;

if($x==0)
{
// SOME CODE
}
else
{
echo "<SCRIPT LANGUAGE='javascript'>DivClos();</SCRIPT>\n";
}

echo "
</body>
</html>
";
?>

faraz aleem
02-03-2007, 07:42 PM
ya i checked the code in which javascript function is called from PHP code,bt when i used the same statement in my code,it didnt call the javascript function.I have seperate JS file and javascript function there,even i wrote the closediv() function in php file bt still result is the same.......actually i m using AJAX,i have php page one in which div style is set to none and on button click i m calling AJAX function which loads the form in tht closed div and make it style to display...Wat i want is to set display style property of div to none so tht i can call it,and for tht i need to call javascript function without any event trigger.For some reason javascript function is not called in my code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum