Friday, 14th October 2011
Follow WikiJava on twitter now. @Wikijava

Adding items to a web form

From WikiJava

Jump to: navigation, search
The author suggests:

buy this book


This example shows you how to put in your web pages a button. When the users click that button they can add any HTML components to the page, including forms. This can, for example, be used in ajax applications

Contents

the article

The 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>


Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Comments on wikijava are disabled now, cause excessive spam.