How can you insert javascript in php code?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which are the best start and end tags to use?

671


What is fetch array in php?

684


Can you pass an array into a function?

650


Write a program to display reverse of any number?

581


Tell me how is it possible to return a value from a function?

642






What are the differences between require and include?

641


Are parent constructors called implicitly inside a class constructor?

599


How do I install php and apache on windows 10?

604


What does $_server mean?

640


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

652


What is php stack?

608


How do you sort an array in php?

628


What does the unlink() function mean?

661


What are PHP Magic Methods/Functions. List them.

641


What is difference between mysql_fetch_array and mysql_fetch_assoc?

579