How can you insert javascript in php code?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does session start do in php?

507


Explain the importance of the function htmlentities.

543


What is pdo classes?

564


What is the difference between echo, print and printf()?

497


What is the use of preg_match in php?

532






What is php artisan serve?

517


Write a hello world program using variable?

535


What are the 5 types of data?

560


How to check if a string contains a character or word in php?

538


What is the use of dual table in mysql?

518


Do you know how to get the ip address of the client?

518


Are php sessions cookies?

506


What is Apache's configuration file typically called?

557


What is php written in?

541


How can you declare a constant variable in php?

564