0
how to insert javascript code in html page.
how to insert javascript code in html page.
<script>
//variable
//function
//objects
//class
//properties
//message box
</script>
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta charset='utf-8' />
<title>JS Demo</title>
</head>
<body>
<p>JS demo</p>
<p id='id1'></p>
<script>
document.getElementById('id1').innerHTML = 'this is body tag occur';
</script>
</body>
</html>
First-js-file.js (creating this file)
//variable
//function
//objects
//class
//properties
//message box
JavaScript.js
function changeColor() {
var name = window.document.getElementById('color');
alert('Your selected color is : ' + name.value);
name.style.backgroundColor = name.value;
window.document.body.style.backgroundColor = name.value;
}
htmlDemo.html
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta charset='utf-8' />
<title>JS Demo</title>
<style type='text/css'>
* {
margin:10px;
padding:0px;
}
select {
width:100px;
}
</style>
<script src='JavaScript.js' type='text/javascript'></script>
</head>
<body>
<span>Select Color name : </span>
<select name='color' id='color' >
<option value='red'>Red</option>
<option value='yellow'>Yellow</option>
<option value='white'>White</option>
<option value='pink'>Pink</option>
<option value='green'>Green</option>
</select>
<button type='button' onclick='changeColor()' value=' Submit '> Submit </button>
</body>
</html>
