Page 274 - Web Applications (803) Class 12
P. 274

<h2>Button Colours</h2>

                    <p>Change the background colour of a button with the background-color prop-
                   erty:</p>
                   <button class=”button”>Green</button><br><br>
                   <button class=”button button2”>Blue</button><br><br>

                   <button class=”button button3”>Red</button><br><br>
                   <button class=”button button4”>Cyan</button><br><br>
                   <button class=”button button5”>Black</button>
                    Output:

























                7.  Write JavaScript code for the OK button to find the factorial of a number entered in a textbox on the webpage.

               Ans.  <html>
                   <head>

                       <title>Factorial Calculator</title>
                   </head>
                   <body bgcolor=”cyan” text=”red”>

                       <h2>Factorial Calculator</h2>
                       <p>Enter a number to calculate its factorial:</p>
                       <input type=”text” id=”number”>

                       <button onclick=”calculate()”>Calculate Factorial</button>
                       <p id=”result”></p>
                       <script>

                           function calculate() {
                     var number = document.getElementById(“number”).value;
                     var factorial = 1;

                     for (var i = 1; i <= number; i++) {
                       factorial *= i;

                     }

                272   Touchpad Web Applications-XII
   269   270   271   272   273   274   275   276   277   278   279