Page 171 - CITS - CSA - TP (Volume 1) - Hindi
P. 171

कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS




           टा  3: गितशील फ़ॉम  एिलम ट बनाएँ

           1  टे  एिडटर ओपन कर
           2  िन िल खत कोड िलख

              <html >

              <head>

              <title>Dynamic Form Elements</title>
              </head>

              <body>

              <div id=”container”>
              <form id=”myForm”>

              <!-- Initially, the form has one input field -->

              <input type=”text” name=”field1” placeholder=”Field 1”>
              <br>

              <button type=”button” onclick=”addField()”>Add Field</button>

              <button type=”submit”>Submit</button>

              </form>
              </div>

              <script>

              function addField() {
              var form = document.getElementById(“myForm”);

              var inputCount = form.getElementsByTagName(“input”).length + 1; // Get the number of existing input fields and increment
                 by 1

              var newInput = document.createElement(“input”); // Create a new input element

              newInput.type = “text”;
              newInput.name = “field” + inputCount; // Assign a unique name to the new input field

              newInput.placeholder = “Field “ + inputCount; // Placeholder text

              newInput.required = true; // Optionally, make the field required
              form.appendChild(newInput); // Append the new input field to the form

              }

              </script>
              </body>

              </html>




                                                           155

                                     CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 42
   166   167   168   169   170   171   172   173   174   175   176