I have a form with checkboxes, these checkboxes store there value in an array when checked this way:
<input type='checkbox' name='listaction[]' value='2010102909103530'>
On submit I check which checkboxes were checked and I do something with it.
My problem occurs when only one item is selected then listaction isn't an array but just a string ...
How do I handle this ?
It starts all with the submit button that firesup desubmit()
These are the handling functions:
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;
}