Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one help me in calling java script function from PHP

JavaScript
<script>
function HideDiv(id)
{
  document.getElementById(id).style.display="block";				
}

</script>


PHP
if($Acidity=="Acidity")
{
        echo"Raj";	
	echo "<SCRIPT LANGUAGE='javascript'>HideDive('Acidity');</SCRIPT>";

}



I need to make the Div Visible.

Thanks!
Posted
Updated 15-Dec-10 2:58am
v3
Comments
Abdul Quader Mamun 15-Dec-10 8:58am    
Use pre tag.
Manfred Rudolf Bihy 17-Dec-10 13:32pm    
Have you checked my answer yet?

Hi Rajesh,

since the pre tag with attribute lang equal to php seems to make some unwanted modifications concerning double quotes I'll post my answer with lang equal to text (not so nicely fomatted but what you read is what I wrote :) ):

JavaScript
<script type="text/javascript">
function HideDiv(id)
{
    document.getElementById(id).style.display="block";
}
</script>


if($Acidity=="Acidity")
{
    echo "Raj";
    echo "<script type='text/javascript'>HideDiv('Acidity');</script>";
}


There are two issues I found in your code:
1. Script tag's attribute to select scripting lanuage is called type
and takes "text/javascript" for javascript code.
2. Function you wrote is named HideDiv(id) you called a function called HideDive(id).


I hope you get it to work with these corrections!


Best Regards,


Manfred

PS: The function should be called ShowDiv if its semantic is to reveal the div and not to hide it.
 
Share this answer
 
v6
try the following code.

PHP
if($Acidity == 'Acidity')
{
echo "Raj";
echo "<Script language='text/javascript'">Hidediv('Acidity');</Script>";
}

I hope this will correct your code.
 
Share this answer
 
v3
Comments
Dalek Dave 28-Dec-10 2:26am    
Edited for Code Block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900