JS Getting Started • Form details one (modify form properties, modify form element values) __js

Source: Internet
Author: User
Real JavaScript Primer · Introduction to document objects (access to the form, create a new page, get the page title) in the article, we've got some basic access to the form, and we're going to drill down to the properties of the form and the simple operation of the form element.

Demo One: According to demand, custom form

You first press the submit submission form, back up, then click to modify the form, and then submit the form, see the effect

Now the point is test.asp, the method is post

Actually do so much not, directly make two attributes Bar Tianhongkun blog NetEase get post

Demo Two: Modify the value of a particular type of element within a form

Form.elements[] Property: In addition to tracking each type of element in a form, the browser retains a list of all the control elements in the form, and the order of the elements is in the HTML position, so it is quite handy for references.

<% @LANGUAGE = "JAVASCRIPT" codepage= "936"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta HTTP-EQUIV = "Content-type" Content = "text/html"; charset=gb2312 "/>
< title > Form details One (modify form properties, modify form element values) </title >
< SCRIPT language = "JavaScript" >
function Gaibian ()
{
var Acti=document.getelementbyid ("select"). value;//get a value with the ID SELECT element
var Mont=document.getelementbyid ("Select2"). value;//ditto
document.form1.action=acti;//Set Value
document.form1.method=mont;//ditto
}
function Bian ()
{
Var form=document.forms[1];//assigns the second form of the current page to the variable form for later reference
for (var i=0;i<form.elements.length;i++)//Loop the largest item in an array of elements within a form
{
if (form.elements[i].type== "text")//if the type of the current element is text
{
Form.elements[i].value= "Tianhongkun";//Then give his value to Tianhongkun.
}
if (form.elements[i].type== "checkbox")//If check box
{
if (form.elements[i].checked)//If selected
{
form.elements[i].checked=null;//Cancel Selection
}
Else
{
Form.elements[i].checked= "Checked"//Just give him a check.
}
}
}
}
</script >

< BODY >
< P

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.