Use checkbox in html as follows: struct [] valuedatastruct Data Structure inputtypecheckboxidmycouse2namemycouse [] valuec ++ C ++ inputtypecheckboxidmycouse3namemycouse [] valuec # C # inputt
Use checkbox in html as follows: form name = frm1 input type = checkbox id = mycouse1 name = mycouse [] value = datastruct Data Structure input type = checkbox id = mycouse2 name = mycouse [] value = c ++ C + + input type = checkbox id = mycouse3 name = mycouse [] value = c # C # input t
Use checkbox in html as follows:
Note that the "[]" character in the checkbox name is used as an array. in php, you can use the foreach method to obtain the selected value.
However, the document. frm1.mycouse []. length method cannot be used in js. Only document. frm1.mycouse. length can be used. In this way, php can only take the last selected mycouse value and cannot obtain all the selected mycouse values.
Solution: document. frm1 ["mycouse []"]. length. Think of the entire form as an array, and use checkbox [] as one of the elements.
Checkbox_mycouse = document. frm1 ["mycouse []"];
For (var I = 0; I <= checkbox_mycouse.length-1; I ++)
{
If (checkbox_mycouse [I]. checked)
Count ++;
}
Alert ('you' + count + 'option is selected. ');
In fact, if name = "mycouse []" is name = "mycouse", it is very simple:
For (var I = 0; I <= document. frm1.mycouse. length-1; I ++)
{
If (document. frm1.mycouse [I]. checked)
Count ++;
}
Author: Zhang Qing (mesh), microblog: http://t.qq.com/zhangking
From mesh horizon: http://blog.why100000.com
Why 100,000 computer learning networks: http://www.why100000.com
2012-8-22