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 api laravel?

0 Answers  


How session works (internal processing of session) ?

3 Answers   ASD Lab, IPSR Solutions,


Can you specify the "new line" character in single-quoted strings?

0 Answers  


List out the predefined classes in PHP?

11 Answers  


i have a string and that string contains the alphanumeric value and i want to hide or semihide the 10 digit telephone number from the string.

0 Answers  






How is a constant defined in a PHP script?

0 Answers  


What is a controller php?

0 Answers  


I created a cookie with the value like '1A2A',now i want to update this value regularly (about 20 times in a minute) with the value '1A2A3A' , 3A is the new value,new value will vary on the request it may be 3A or 4A or 100A ,some times the cookie is updating with new value but not every time.Can any body suggest the solution

1 Answers  


Tell me what is use of in_array() function in php?

0 Answers  


What is a session in php?

0 Answers  


What is isset function in php?

0 Answers  


Can php replace javascript?

0 Answers  


Categories