A little experience of using prototype (IV.)

Source: Internet
Author: User

Using the Field object to Manipulate table fields (Api:http://www.prototypejs.org/api/form)

Sample code:

<script src= "Prototype-1.6.0.2.js" type= "Text/javascript" ></script>
<body>
<input id= "Text1" type= "text"/><br>
<input id= "Text2" type= "text"/><br>
<input id= "Text3" type= "text"/><br>
<input id= "Text4" type= "text" value= "xxxxxxxxx"/><br>
<select size= "3" id= "St1" >
<option>Java</option>
<option>Struts</option>
<option>Spring</option>
</select>
<br>
<input type= "button" value= "AA" onclick= "field.clear (' Text1 ', ' text2 ', ' Text3 ')"/><br>
<input type= "button" value= "BB" onclick= "Alert (field.present (' Text1 ', ' text2 ', ' Text3 ')") "/><br>
<input type= "button" value= "CC" onclick= "Field.focus (' Text3 ')"/><br>
<input type= "button" value= "dd" onclick= "Field.select (' Text4 ')"/><br>
<input type= "button" value= "ee" onclick= "field.activate (' St1 ')"/><br>
</body>
<script>
</script>

Function Description:

1.clear: Clears all form field values passed into this method.

2.present: Determines whether all form fields have a value.

3.focus: Specifies the focus.

4.select: Select the text within the form field (text box only, text is valid).

5.activate: With Select and one more feature: if the target element is not selected, the focus moves to the target element.

In addition, you can use the Form.element object with the sample code as follows:

<script src="prototype-1.6.0.2.js" type="text/javascript"></script>
<body>
<input id="text1" name="text1" type="text" /><br>
<input type="button" value="aaa" onClick="alert (Form.Element.serialize('text1'));"/><br>
<input type="button" value="bbb" onClick="alert (Form.Element.getValue('text1'));"/><br>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.