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

How to increase the execution time of a PHP script?

537


What is session data?

543


What type of operation is needed when passing values through a form or an url?

538


Write a program in php to print a table of a number?

515


What are the advantages of triggers in php?

479






What the use of var_dump()?

590


What is cookie in php with example?

534


What are traits?

712


What is the use of anonymous function in php?

557


Inside a php function, what param needs to be set in order to access a global variable?

551


What are include() and require() functions?

524


Tell me how to create a session? How to set a value in session? How to remove data from a session?

514


What is php mean?

572


What are the data types in php?

553


How to connect to mysql from a php script?

569