How can you insert javascript in php code?

Answers were Sorted based on User's Feedback



How can you insert javascript in php code?..

Answer / atanu

<?php
echo"<script language='javascript'>

</script>
";
?>

Is This Answer Correct ?    101 Yes 31 No

How can you insert javascript in php code?..

Answer / vivek srivastava

You can write Java Script in PHP in a very simple way so as
I did:

<?php
some php code...
?>

<script type="text/javascript">
function someFun()
{
function code....
}
</script>

<?php
some php code...
?>

Is This Answer Correct ?    72 Yes 18 No

How can you insert javascript in php code?..

Answer / sivarajan

<?php echo "<script>alert('Insert Javascript in PHP');
</script>"; ?>

Is This Answer Correct ?    55 Yes 11 No

How can you insert javascript in php code?..

Answer / webguy

Mukesh(watch out for syntax errors) and atanu are right.
VIvek seemed have misunderstood the question. It's more of
injecting JS code within PHP code segment like this:

<?php
echo "<script type='text/javascript'>";
echo "alert('jams bond');";
echo "</script>";
?>

OR

<?php
echo "<script type='text/javascript'>alert('jams
bond');</script>";
?>

Is This Answer Correct ?    24 Yes 8 No

How can you insert javascript in php code?..

Answer / moron

none off your example works... why are you posting shit that
doesent work? stupid morons

Is This Answer Correct ?    14 Yes 3 No

How can you insert javascript in php code?..

Answer / prantik gautam

<?php
$var1=rand(0,9);
$var2=rand(0,9);
$var3=rand(0,9);
$var4=rand(0,9);
$var5=rand(0,9);
$var6=rand(0,9);
$col='#'.$var1.$var2.$var3.$var4.$var5.$var6;
echo '<script type="text/javascript">alert("The color code
'.$col.' had been poped up by using javascript which is used
in PHP");</script>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Change Background Color of DIV</title>
<style type="text/css">
#bk{
width:300px;
height:300px;
background-color:<?php echo $col; ?>;
border:1px solid #000000;
}
</style>
</head>
<body>
<div id="bk">DIV Changing its background</div>
</body>
</html>

Is This Answer Correct ?    18 Yes 8 No

How can you insert javascript in php code?..

Answer / mukesh purohit

<?php
echo "<srcipt type='language'>";
echo "alert('jams bond');";
echo "<script>";
?>

Is This Answer Correct ?    23 Yes 18 No

How can you insert javascript in php code?..

Answer / muhammad adeel qureshy

<?php
$var1=rand(0,9);
$var2=rand(0,9);
$var3=rand(0,9);
$var4=rand(0,9);
$var5=rand(0,9);
$var6=rand(0,9);
$col='#'.$var1.$var2.$var3.$var4.$var5.$var6;
echo '<script type="text/javascript">alert("The color code
'.$col.' had been poped up by using javascript which is used
in PHP");</script>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Change Background Color of DIV</title>
<style type="text/css">
#bk{
width:300px;
height:300px;
background-color:<?php echo $col; ?>;
border:1px solid #000000;
}
</style>
</head>
<body>
<div id="bk">DIV Changing its background</div>
</body>
</html>

Is This Answer Correct ?    12 Yes 10 No

How can you insert javascript in php code?..

Answer / suno32

{echo '<script language="javascript"></script>';}

Is This Answer Correct ?    2 Yes 3 No

How can you insert javascript in php code?..

Answer / naqiya

example
?>
<script language='javascript'>
document.location.href=".php";
</script>
<?php
}
?>

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More PHP Interview Questions

What is the Diff. Between echo() and Print() in PHP?

29 Answers   CoreNet, Priya, QueenZend, Sky InfoTech, Syntel,


How do I see how many pages per session in google analytics?

0 Answers  


How many php based companies in bangalore and chennai and over all india ? most of the persons saying for 2 years and 3 years they will be getting less than 15k per month how far is it true ? is it good scope for experience people can any one tell the exact experience pay for php developers one yr experience how much sal we expect ? two yr experience how much sal we expect ? three yr expereince how much sal we expect ? please kindly reply to the above questions as an experts you only please kindly judge and tell your practical experience in PHP ?

3 Answers  


what do you mean by webserver's document root?

3 Answers  


Can you use both this () and super () in a constructor?

0 Answers  






What is array and function?

0 Answers  


What is the use of mysql_real_escape_string in php?

0 Answers  


Explain what is the difference between for and foreach?

0 Answers  


How can I make a script that can be bilingual (supports english, german)?

0 Answers  


Write a program to display a table of any given number?

0 Answers  


Whether it is possible to share a single instance of a memcache between multiple php projects?

0 Answers  


Explain what are the two main string operators?

0 Answers  


Categories