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.