Ajax code to automatically get the form element values in the sample code _ajax related

Source: Internet
Author: User

When we use Ajax, we usually need to get the form element value and then send it to the backend server-side program for processing. If the table cell is not much, we often get the form element value, but if the form element is very much, then need to use the Post method to get the form element value, then how to get the form element value? The following gives a section of JS code to automatically get the value of the form elements.

function getformquerystring (frmid)//frmid is the ID number of the form, first name an ID number
{var frmid=document.getelementbyid in the form form
( FRMID);
var i,querystring = "", and = "";
var item;
var Itemvalue;
for (i=0;i<frmid.length;i++)
{
item = Frmid[i];
if (item.name!= ')
{
if (Item.type = = ' Select-one ')
{
Itemvalue = item.options[ Item.selectedindex].value;
}
else if (item.type== ' checkbox ' | | | item.type== ' Radio ')
{
if (item.checked = = False)
{
continue;< c20/>}
itemvalue = Item.value;
}
else if (item.type = ' button ' | | item.type = ' Submit ' | | item.type = ' reset ' | | item.type = = ' image ')
{
cont inue;
}
else
{
itemvalue = item.value;
}
Itemvalue = Escape (itemvalue);
QueryString + + + item.name + ' = ' + itemvalue;
And= "&";
}
return querystring;
}

Call method: Call the above JS function directly in Ajax to get the value of all the elements in the form.

Related Article

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.