【发布时间】:2011-01-27 15:37:30
【问题描述】:
我有一个带有复选框的表单,这些复选框在以这种方式检查时将值存储在一个数组中:
<input type='checkbox' name='listaction[]' value='2010102909103530'>
在提交时,我会检查哪些复选框已被选中,然后我会对其进行处理。
我的问题发生在只选择一个项目然后 listaction 不是一个数组而只是一个字符串...
我该如何处理?
一切都从触发 desubmit() 的提交按钮开始
这些是处理函数:
function desubmit()
{
if(get_args()==false) {alert("U hebt geen treinen geselecteerd!");return false;}
if(labelling(true)) return false;
}
function Check(chk)
{
for (i=0; i < chk.length; i++) chk[i].checked=document.ListActionForm.Check_ctr.checked ;
}
function labelling(s)
{
notrains="U hebt geen treinen geselecteerd!"
selectval=document.ListActionForm.la.options[document.ListActionForm.la.selectedIndex].value;
if(selectval=='exportoptions') {popUpWin('form.php?exportconfig=1','console3',470,470);}
else if(selectval=='newlabel'&&!s) {jPrompt('Nieuwe Lijst:','Default', 'Maak nieuwe lijst (Max 20 karakters)', function(r) {if(r) {if(r.length>20){alert("Gekozen naam lijst mag maximum 20 tekens lang zijn (Overige tekens worden automatisch verwijderd)");r=r.substr(0,20);};document.ListActionForm.newlabel.value=r;document.getElementById('shownewlabel').innerHTML='[ Nieuwe Lijst: '+r+' ]';}});document.getElementById('popup_prompt').maxlength=5;}
else if(selectval=='export:pdf') {if(arg=get_args()) get_page('/PDF/pdf.php','ids',arg);else alert(notrains);}
else if(selectval=='export:csv') {if(arg=get_args())get_page('?export=csv','ids',arg);else alert(notrains);}
else if(selectval=='export:xlsapp') {if(arg=get_args())get_page('?export=excelvbs','ids',arg);else alert(notrains);}
else if(selectval=='export:xlsapptxt') {if(arg=get_args())get_page('?export=excelvbstxt','ids',arg);else alert(notrains);}
else return false;
return true;
}
function get_args()
{
s=chkboxa2str(document.ListActionForm['listaction[]']);
if(s.length<8)return false;
else return s;
}
function chkboxa2str(chkbox_a) {
var list = "";
for(var i = 0; i < chkbox_a.length; i++){ if(chkbox_a[i].checked) { list += chkbox_a[i].value + " "; } }
return list;
}
【问题讨论】:
-
正在考虑修改函数 chkboxa2str(chkbox_a)
标签: javascript html forms checkbox