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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.