Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to change the div background color on every
refresh..guys can u help me out.

Answers were Sorted based on User's Feedback



how to change the div background color on every refresh..guys can u help me out...

Answer / guest

Try with the following code.
<html>
<body onload="changeColor()">
<script type="text/javascript">
var color=new Array(6);
color[0]="green";
color[1]="#eeeeee";
color[2]="#99CCFF";
color[3]="lavender";
color[4]="pink";
color[5]="#669999";
function changeColor()
{
var ranNum= Math.floor(Math.random()*6);
document.getElementById('div1').style.backgroundColor=color[ranNum];
}
</script>
<div id="div1" name="div1"
style="height:500px;"><center>Changing Color of
div</center></div>
</body>
</html>

Is This Answer Correct ?    27 Yes 5 No

how to change the div background color on every refresh..guys can u help me out...

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;
?>
<!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 4 No

how to change the div background color on every refresh..guys can u help me out...

Answer / kapil dhiman

<?php

// Class
class ChangeDivColor{

public function __construct(){

$value= array("#000000","#CC0000","#009900","#6600CC","#FFFF00");
$rand_keys=array_rand($value,2);

echo '<div style="height:200px; width:200px; float:left; background:'.$value[$rand_keys[0]].';"></div>';


}
}

$obj= new ChangeDivColor()


// inline coding
$value= array("#000000","#CC0000","#009900","#6600CC","#FFFF00");
$rand_keys=array_rand($value,2);
?>
<div style="height:200px; width:200px; float:left; background:<?=$value[$rand_keys[0]]?>;"></div>

Is This Answer Correct ?    5 Yes 2 No

Post New Answer

More PHP Interview Questions

What are different ways to redirect from on page to other?

9 Answers  


recurring account in PayPal payment gateway?

1 Answers   A1 Technology, HBL, HBL Power Systems, IBM,


How does csrf token work?

0 Answers  


How data or variable can be receive or send from PHP to HTML page??

3 Answers   TCS,


How to convert a json string to an array in php?

0 Answers  


how to upload more than 50 mb? i tried but session was expired....certain time .....i was set session duration three days .... how to rectified? if any one know that post ur answer as soon as possible?already i was increase php.ini and set Also increase Memory_limit Post_max_size upload_max_filesize..........but not working......

0 Answers  


Is php still relevant 2019?

0 Answers  


What is faster in php?

0 Answers  


What is overloading and overriding in oop?

0 Answers  


What is the difference between echo and print statement?

11 Answers   Rushmore Consultancy,


What does csrf token mean?

0 Answers  


How to create connection in php?

0 Answers  


Categories