Jump to content

Validating checkboxes from MYSQL value


biggieuk

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/133263-validating-checkboxes-from-mysql-value/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.