Check the multiple options (check box) in PHP + JS

Source: Internet
Author: User

In PHP, to obtain the value of the check box, you must name the name of the check box as an array.

Then, you can obtain the value in $ _ Get ["multiplayname"] or $ _ put ["multiplayname"]. However, to determine whether the user has selected the tag, you must select one option for multiple projects, otherwise, the form cannot be submitted!

After searching for documents on the Internet for half a day, the system basically processes the names of multiple selection boxes into arrays and checks whether the checked value is selected. As follows:

VaR CH = "";
For (VAR I = 0; I <document. Forms. Check. length; I ++)
{
If (document. Forms. Check [I]. Checked)
Ch = CH + document. Forms. Check [I]. value;
}
If (CH = "")
{
Alert ("select the item you want to delete! ");
Return false;
}

However, in actual use, PHP has named the name of the checkbox as an array []. This call will fail!

So I came up with a compromise!

Is to use document. getelementbyid ("ID") to obtain its value, and the idea is similar to array [manual array], as follows:

JS:

Function checkspace (checkstr ){
VaR STR = '';
For (I = 0; I <checkstr. length; I ++ ){
STR = STR + '';
}
Return (STR = checkstr );
}
<Input name = "functionsub []" type = checkbox id = "functionsub3" value = Member registration system>
Member registration system </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub4" value = Information Retrieval System>
Information Retrieval System </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub5" value = community forum system>
Community Forum System </TD>
</Tr>
<Tr>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub6" value = customer feedback system>
Customer Feedback System </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub7" value = Link Management System>
Link Management System </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub8" value = download system>
Download System </TD>
</Tr>
<Tr>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub9" value = online inquiry system>
Online Inquiry System </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub10" value = online recruitment system>
Online recruitment system </TD>
<TD> <input name = "functionsub []" type = checkbox id = "functionsub11" value = traffic statistics system>
Traffic Statistics System

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.