There are many ways of accessing form elements, of which the easiest is by using the cross-browser W3C DOM
document.getElementById()
method. Before we learn more about this method, it would be useful to know something about the Document Object Model (DOM), the concept of HTML nodes or elements, and the concept of containers.
Each time you load an HTML page, the web browser generates an internal representation of the page in the form of an inverted tree structure. Let us look at a simple form. We will use this form later to demonstrate the use of the getElementById method.
<form name ="subscribe" id="subscribe_frm" action="#"> Your Name: <input type="text" name="name" id="txt_name" /> Your Email: <input type="text" name="email" id="txt_email" /> <input type="button" name="submit" value="Submit" onclick="processFormData();" /> </form>
There are elements such as <input/> and containers like <form> </form> Each element can have attributes associated with it, such as:
<input type="text" name="name" id="txt_name">
ere, the <input/> element has three attributes: type, name and id. The idattribute uniquely identifies this particular element.
0 comments:
Post a Comment