biggieuk Posted November 19, 2008 Share Posted November 19, 2008 Hi all, I have a little problem which im struggling to get my head around. In my MYSQL session table i have a field called 'practical' which contains either a 1 or 0, based on if the session is a practical or not. My PHP form contains two repeating tables, one containing morning sessions and one with afternoon sessions followed by a checkbox. I have appended these values in a hidden field using: <input type="hidden" name="practicalAM1[]" id="<?=$sessionPM1['groupid']; ?>" value="<?=$row_sessionAM1['practical']; ?>"/> These checkboxes are named: checkedAM1[] & checkedPM1[]. I now need to validate this form so that only one Practical session is checked from the whole of checkedAM1 and checkedPM1. I tried the following test but do not receive a popup when a practical session is selected: function ChkPractical(oN,aM){ var myObj = document.forms['form1'].elements[oN]; // cycle through radio buttons and test if hidden value is 1 var i = 0; for(var j=0;j<myObj.length;j++){ if(myObj[j].value ==1){ i++; } } if (i==1){ myObj[0].focus(); alert(aM); return false; } else { return true; } } its use: ChkPractical('practicalAM1[]', 'Please Select Only 1 Practical Session') If anybody knows a better way or where im going wrong then your help is very much appreciated! thanks. Quote Link to comment https://forums.phpfreaks.com/topic/133263-validating-checkboxes-from-mysql-value/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.