<script language="javascript">
function check(){
var strchoice="";
for(var i=0;i<document.info.choice.length;i++){
if (document.info.choice[i].checked) {
strchoice=strchoice+document.info.choice[i].value+",";
}
} if (!document.info.choice.length) {
if (document.info.choice.checked) {
strchoice=document.info.choice[i].value;+","
}
}
strchoice=strchoice.substring(0,strchoice.length-1);
document.info.choiceid.value=strchoice;
alert(document.info.choiceall.value);
}
</script>
用这个把,那获得全部的值
function check(){
var strchoice="";
for(var i=0;i<document.info.choice.length;i++){
if (document.info.choice[i].checked) {
strchoice=strchoice+document.info.choice[i].value+",";
}
} if (!document.info.choice.length) {
if (document.info.choice.checked) {
strchoice=document.info.choice[i].value;+","
}
}
strchoice=strchoice.substring(0,strchoice.length-1);
document.info.choiceid.value=strchoice;
alert(document.info.choiceall.value);
}
</script>
用这个把,那获得全部的值
<input type="checkbox" name="checkbox[]" value="123">
123
<input type="checkbox" name="checkbox[]" value="234">
234
<input type="checkbox" name="checkbox[]" value="asd">
asd
<input type="checkbox" name="checkbox[]" value="qwe">
qwe
<input name="" type="submit">
</form>
<?print_r($checkbox);?>
<input type=\"hidden\" name=\"choiceid\"><input type=submit value=\"获得\">
choice是checkbox name=choice
$_POST['checkboxname'],这是一个数组,checkboxname的值就存在于这个数组中,第一个就是 $_POST['checkboxname'][0],以此类推
这不是我的方法,这是php的约定。
php对表单变量命名时有一个小小的要求:同名的表单变量要写成数组形式,否则他不认得。
http://www.blueidea.com/bbs/NewsDetail.asp?id=1256952
===================================================
后台读取选中的值
print_r($_POST['checkbox'])将其保存为asp的多选框格式
echo implode(",",$_POST['checkbox'])