Skip to main content

Execise 8: : Change Button Properties Onchange Event (Interactive)

 

CODE FOR HTML;

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Change Button Properties</title>

<link rel="stylesheet" href="Exercise8ChangeButton.css">

</head>


<body>

<fieldset>

<h1> Change Button Properties Onchange Event </h1>


<h3> Enter Color: </h3>

<input type="text" id="input1"/> <br>

<h3> Enter number: </h3>

<input type="number" id="input2" onchange="onchangeevent()"/> <br> <br> <br>

<input class="btn" type="button" id="display1">

<input class="btn" type="button" id="display2">

<input class="btn" type="button" id="display3">

<input class="btn" type="button" id="display4">

<input class="btn" type="button" id="display5">


</fieldset>


<script>

function onchangeevent()

{

document.getElementById("input2");

n=document.getElementById("input2").value;

c=String(document.getElementById("input1").value);

switch(Number(n))

{

case 1: document.getElementById("display1").style.background=c;

document.getElementById("display1").value=c;

break;

case 2: document.getElementById("display2").style.background=c;

document.getElementById("display2").value=c;

break;

case 3: document.getElementById("display3").style.background=c;

document.getElementById("display3").value=c;

break;

case 4: document.getElementById("display4").style.background=c;

document.getElementById("display4").value=c;

break;

case 5: document.getElementById("display5").style.background=c;

document.getElementById("display5").value=c;

break;

default: document.getElementById("display1").style.background=c;

document.getElementById("display1").value=c;

break;

}

}

</script>

</body>

</html>


CODE FOR CSS;


* {

box-sizing: border-box;

}


h1.font1 {

margin-left: 30%;

}


fieldset {

width: 60%;

background-color: #cbc6dc;

padding-left: 30px;

padding-right: 30px;

padding-bottom: 8%;

margin-top: 30px;

margin-left: 19%;

border: 0;

}


.btn {

width: 100px;

height: 80px;

border-radius: 10px;

background-color: white;

text-shadow: -1px 1px 0 #000000, 1px 1px 0 #000000, 1px -1px 0 #000000, -1px -1px 0 #000000;

font-size: 20px;

font-weight: bold;

float: left;

margin-left: 5px;

}

Comments

Popular posts from this blog

Exercise 10: Animation (Finals Web Prog)

(Code for HTML:) <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Exercise 010 Animated Web page</title> <link rel="stylesheet" href="Exercise10AnimatedWebpage.css"> </head> <body> <div> <h1 style="font-size:40px;"> ABOUT MYSELF  </h1> </div> <br> <br> <br> <br> <br> <br> <br> <br>  <p style="text-align: justify; text-indent: 50px;">  Hi I'm Jillian Marren Dela Cruz. You can call me "Jill or Jillian" i'm currently 3rd year Multimedia Arts Student. 20 years of Age. I chose multimeida because i want to enchance my skills and i'm willing to learn about everything. I'm November Babies and My zodiac sign is Sagittarius. The Sagittarius Traits is Curious and energetic, Sagittarius is one of the biggest travelers among all...