Page 79 - DCAP202_Fundamentals of Web Programming
P. 79

Fundamentals of Web Programming




                    Notes             Objects contain properties and methods;
                                      Arrays contain a sequential list of elements;
                                   Functions contain a collection of statements.




                                      Task  Compare and contrast primitive data types and composite data types.

                                   Self Assessment

                                   Fill in the blanks:
                                   11.  .......................... data types are the types that can be assigned a single literal value.

                                   12.  .......................... are rows of characters enclosed in either double or single quotes.

                                   6.7 Creating Values

                                   Here, we will demonstrate the use of JavaScript for accessing the values of form elements.

                                   6.7.1 Value for Text Input Element

                                                             Figure 6.3:  Text Input  Element




                                   To obtain a reference to a text input element, here is some sample code:
                                   oText  =  oForm.elements[“text_element_name”];  OR
                                   oText  =  oForm.elements[index];
                                   In the code above, "index" is the position of the  element in  the 0-based elements array, and
                                   oForm is the form object reference obtained using the document.forms collection:
                                   oForm  =  document.forms[index];
                                   To get the value of the text input element, we can use the value property of the text input object:
                                   text_val  =  oText.value;
                                   As an example, if we have the following text input element:
                                   <input  type="text"  name="name"  id="txt_name"  size="30"  maxlength="70">
                                   We can access the value of the element like this:
                                   name  =  oForm.elements["name"].value;

                                   6.7.2 Value for Text  Area Element

                                                             Figure 6.4:  Text Area  Element















          72                                LOVELY PROFESSIONAL UNIVERSITY
   74   75   76   77   78   79   80   81   82   83   84