jquery Determines if checkbox is selected

Source: Internet
Author: User

Parameter description:

1.checkName: Indicates the name value of the check box

2.updateFile: Indicates that the database needs to manipulate the field, the project needs to update a field, so this place is the need to update the field, can be changed depending on the situation

3.formName: Represents the name value of the page form, if the program is written in the page, you can directly write the name value of the form, such as Form NAME=FORM2, you can form2.action= xxx; Form2.submit ();

But if you put the program in an external JS file, you need to get the form DOM element in the page

Note: The 1.jquery version is Jquery-1.7.2.js

2. Some programs are checked for. attr ("checked") ==true judgment, but may be a jquery version problem, not available, can be alert ((Get checkbox) when used. attr ("checked"); see what value

3. Remember that you cannot get the value in input if you set enctype= "Multipart/form-data" in the form

Http://bjsmx.taobao.com

function deletestring (checkname,updatefile,formname)

{

var deletestring= "";

var checklength=$ (": Checkbox[name=" +checkname+ "]"). Lengh;

for (Var i=0;i<checklength;i++)

{

if ($ (": Checkbox[name=" +checkname+ "]:eq (" +i+ ")"). attr ("checked") = = "Checked")

{

deletestring+=$ (": Checkbox[name=" +checkname+ "]:eq (" +i+ ")"). Val () + ",";

}

}

if (deletestring== "")

{

Alert ("No check Value");

return false;

}

Else

{

Deletestring=deletestring.substring (0,deletestring.length-1);

if (window.confirm ("OK delete") ==true)

{

$ ("form[name=" +formname+ "]") [0].action= "xxxxxxx?deletestring=" +deletestring+ "&updatefile=" +updateFile;

$ ("form[name=" +formname+ "]") [0].submit ();

}

}

}

Http://bjsmx.taobao.com

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.