How to change background using Java script or java codes?



Perhaps webmaster want to give choice to the audience to change the background colour using the drop down. In such a scenario we use Java codes to change the back ground color. So in this blog we will try to change the background colour of the page with the use of Java program.

First go to run dialogbox and open notepad.

Save the file using changebackground,html file name to specific location.

Paste the following code and save the file by pressing ctrl+S


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Change background using Java code</title>
</head>
<body>
</form> 
<script language="javascript">
function clrchange(SelectedColor)
{
    document.bgColor=SelectedColor;
}
</script>

<select id=s1 onchange="clrchange(this.value);">
<option id="r1" onmouseover="cha(this.id,this.value);" value="select">Select color</option>
<option id="r2" onmouseover="cha(this.value);" value="blue">blue</option>
<option id="r3" onmouseover="cha(this.value);" value="green">green</option>
<option id="r4" onmouseover="cha(this.value);" value="yellow">yellow</option>
<option id="r5" onmouseover="cha(this.value);" value="orange">orange</option>
<option id="r6" onmouseover="cha(this.value);" value="magenta">magenta</option>
<option id="r7" onmouseover="cha(this.value);" value="cyan">cyan</option>
<select>
</body>
</html>
Now open the file using the browser.




Select the colour from the dropdown to see the changes.





We hope that this blog has been useful to all beginners who are trying to learn Java programming for software development, website development or application development.In case you are searching for full stack java developers then you can contact most reputed Java software development company now.

Post a Comment

0 Comments