Adding items to a web formFrom WikiJavabuy this book
the articleThe following code adds to any page a button to add a new question. When the user clicks on the button the 'onClick()' event is captured and the function 'addQuestion()' is called. Add question calls the 'document.createElement()' standard function to create a new HTMLelement. By default the new element is appended in an invisible part of the DOM of the page. 'addQuestion()' then fills the 'innerHTML' field of the new HTMLElement with the relevant html strings. At the end 'addQuestion()' calls the 'HTMLfield = document.getElementById()' standard function to find the element in where to append the new HTMLElement, and calls the function 'HTMLfield.appendChild()' to append the HTMLElement created to the elements contained in the HTMLfield. the code for: add question button<script type="text/javascript">// </script> <div id = "questions"> </div> <div class="submit"> <button onClick="addQuestion();"> Add new question </button> </div>
|
