Page 272 - Web Applications (803) Class 12
P. 272
<input type=”button” onclick=”changeColor(‘red’)” value=”Red”>
<input type=”button” onclick=”changeColor(‘yellow’)” value=”Yellow”>
<input type=”button” onclick=”changeColor(‘green’)” value=”Green”>
</body> </html>
Output:
5. Write JavaScript code to change the text displayed on the button upon clicking it.
Ans. <html>
<script>
function change() {
document.getElementById(“Btn”).value = “Value is changed!”;
}
</script>
<body>
<p>Click on “My Button” to display its value attribute.</p>
<button id=”Btn” name=”B1” value=”Button1” onclick=”alert(this.value)”> But-
ton1 </button>
<p>Click on “Try Out” to change the value attribute of “Button 1”.</p>
<button onclick=”change()”>Try Out</button>
270 Touchpad Web Applications-XII

