Hi,
I have a form which has three sets of radio button groups all containg either "pass" or "fail" for each group at form load all radios are unchecked so that the user has to select either "pass" or "fail" for each group.
the following code checks to make sure each radio group has a selection
I then have the following for the submit button
This works OK, however I also want to check that if all the radios are selected and one or all have a "fail" then check to see if a reject qty has been entered for that group. to this end I have created the following code
this code also works OK on it's own however I would like to combine these 2 sets of code into 1 so that when the user tries to submit first it checks using checkForm(f)to make sure that either "pass" or "fail" has been selected for each radio group if not show the alert, if that check is OK then check to see if there are any fails using checkFails(), if that is OK then submit the form othwise show the appropiate message.
I really would appreciate any help as I have no idea how to implement this
Regards
Paul
I have a form which has three sets of radio button groups all containg either "pass" or "fail" for each group at form load all radios are unchecked so that the user has to select either "pass" or "fail" for each group.
the following code checks to make sure each radio group has a selection
Code:
<script type="text/javascript">
function checkForm(f){
for (var els = f.elements, radio_groups = {}, i = els.length - 1; i > -1; --i)
if(els[i].type && els[i].type == 'radio' && !radio_groups[els[i].name])
radio_groups[els[i].name] = els[i].checked;
for (var p in radio_groups)
if (!radio_groups[p]){
alert('Please Check Either Pass Or Fail\nFor Each Pass/Fail Group !');
return false;
}
return true;
}
</script>
Code:
onSubmit="return checkForm(this)"
Code:
<script type="text/javascript">
function checkFails(){
var errMessage = "";
var pfdim = document.forms["frmTK"].radDim;
var pfqb = document.forms["frmTK"].radQB;
var pfwa = document.forms["frmTK"].radWarp;
var dimrej = document.frmTK["txtDimRej"].value;
var bqrej = document.frmTK["txtQBRej"].value;
var warprej = document.frmTK["txtWarpRej"].value;
//Check Dimension Radio Group
for(var i = 0; i < pfdim.length; i++) {
if(pfdim[i].checked == true) {
statuspfdim = pfdim[i].value;
}
}
//Check BQ Radio Group
for(var i = 0; i < pfqb.length; i++) {
if(pfqb[i].checked == true) {
statuspfqb = pfqb[i].value;
}
}
//Check Warp Radio Group
for(var i = 0; i < pfwa.length; i++) {
if(pfwa[i].checked == true) {
statuspfwa = pfwa[i].value;
}
}
if (statuspfdim == "Fail" && dimrej == "")
{
errMessage += "Dimensions = Fail, Please Enter Number Of Sheets Rejected !\n";
}
if (statuspfqb == "Fail" && bqrej == "") {
errMessage += "Board Quality = Fail, Please Enter Number Of Sheets Rejected !\n";
}
if (statuspfwa == "Fail" && warprej == "") {
errMessage += "Warp = Fail, Please Enter Number Of Sheets Rejected !\n";
}
if (errMessage != "")
{
alert(errMessage);
return false;
}
}
</script>
I really would appreciate any help as I have no idea how to implement this
Regards
Paul