Page 374 - Web_Application_v2.0_C12_Fb
P. 374
<H1>Person Creator</H1>
<SCRIPT>
function createPerson(name, age) {
var person = { name: name, age: age };
document.getElementById("person-info").innerHTML = "Name: " + person.name +
", Age: " + person.age;
}
</SCRIPT>
<FORM ID="person-form">
<LABEL FOR="name">Name:</LABEL>
<INPUT TYPE="text" ID="name" NAME="name"><BR><BR>
<LABEL FOR="age">Age:</LABEL>
<INPUT TYPE="number" ID="age" NAME="age"><BR><BR>
<Button type="button" onclick="createPerson(document.getElementById('name').
value, document.getElementById('age').value)">
Create Person
</BUTTON>
</FORM>
<DIV ID="person-info"></DIV>
</BODY>
</HTML>
Output of the preceding code is as follows:
5. Write JavaScript code for changing background colour of the web page on the click of a button. Create
multiple such buttons for different colours.
Ans. <!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>CHANGE BACKGROUND COLOUR</TITLE>
</HEAD>
<BODY>
<H2>BACKGROUND COLOR CHANGER</H2>
372 Touchpad Web Applications (Ver. 2.0)-XII

