I had posted a similar question earlier. I couldnot get the exact feedback I needed. So I am posting this question again. I hope I will find a solution to this problem.
I have the a FORM for rearranging some records (number of records is dynamic).
The code for the Form is :
<SCRIPT LANGUAGE="JavaScript">
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el.type == "radio") {
var radiogroup = el[el.name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
//alert("item checked for Section "+ el.name +" is." + radiogroup[j].value);
break;
}
}
if(!itemchecked) {
//alert("Please choose a number for each Section "+ el.name +".");
alert("Please choose a number for each Section.");
if(el.focus)
el.focus();
return false;
}
}
}
var itemunique = false;
for(var m = 0 ; m < el.length ; ++m) {
var count = 0;
for(var k = 0 ; k < el.length ; ++k) {
var radiogroup1 = el[el[k].name];
if(radiogroup1[m].checked) {
count = count + 1;
document.write(radiogroup1[k].value);
//itemunique = true;
//alert("item checked for Section "+ el.name +" is." + radiogroup[j].value);
//break;
}
}
if(!count == 1) {
alert("Please choose a unique number for each Section .");
//if(el.focus)
//el.focus();
return false;
}
else { return true;}
}
return true;
}
</SCRIPT>
<Form name='RearrangeSectionForm' Method='POST' Action='includes/updateSectionOrder.asp' onsubmit='return checkRadios(this);'>
<table>
<tr> <td>Current Order</td>
<td>Section Name</td>
<td>Desired Order</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> 1 2 3 </td>
</tr>
<tr>
<td>1</td>
<td>abc</td>
<td>
<input type='radio' value='1' name='R1' ID='Radio1'>
<input type='radio' value='2' name='R1' ID='Radio2'>
<input type='radio' value='3' name='R1' ID='Radio3'>
</td>
</tr>
<tr>
<td>2</td>
<td>pqr</td>
<td>
<input type='radio' value='1' name='R2' ID='Radio4'>
<input type='radio' value='2' name='R2' ID='Radio5'>
<input type='radio' value='3' name='R2' ID='Radio6'>
</td>
</tr>
<tr>
<td>3</td>
<td>xyz</td>
<td>
<input type='radio' value='1' name='R3' ID='Radio7'>
<input type='radio' value='2' name='R3' ID='Radio8'>
<input type='radio' value='3' name='R3' ID='Radio9'>
</td>
</tr>
<tr>
<td colspan='3'><input type='submit' value='Update Section Order' name='Save'></td>
</tr>
</table>
</Form>
The first part of the javascript validation code is to check if atleast one button in every radio group is checked. This works fine.
The second part in the javascript (highlighted in red) is to make sure that only one radio button is checked in each radio group having the same order( or value). (i.e., if Radio group R1 is checked and has a value of 2, then R2 and R3 should not have any radio button checked with value =2.I am having a problem validating this . Please remember that the number of records to be rearranged is dynamic but will always have the same number of radio buttons across rows and columns.
Any help will be greatly appreciated.
Thank you.
PKS.
I have the a FORM for rearranging some records (number of records is dynamic).
The code for the Form is :
<SCRIPT LANGUAGE="JavaScript">
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el.type == "radio") {
var radiogroup = el[el.name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
//alert("item checked for Section "+ el.name +" is." + radiogroup[j].value);
break;
}
}
if(!itemchecked) {
//alert("Please choose a number for each Section "+ el.name +".");
alert("Please choose a number for each Section.");
if(el.focus)
el.focus();
return false;
}
}
}
var itemunique = false;
for(var m = 0 ; m < el.length ; ++m) {
var count = 0;
for(var k = 0 ; k < el.length ; ++k) {
var radiogroup1 = el[el[k].name];
if(radiogroup1[m].checked) {
count = count + 1;
document.write(radiogroup1[k].value);
//itemunique = true;
//alert("item checked for Section "+ el.name +" is." + radiogroup[j].value);
//break;
}
}
if(!count == 1) {
alert("Please choose a unique number for each Section .");
//if(el.focus)
//el.focus();
return false;
}
else { return true;}
}
return true;
}
</SCRIPT>
<Form name='RearrangeSectionForm' Method='POST' Action='includes/updateSectionOrder.asp' onsubmit='return checkRadios(this);'>
<table>
<tr> <td>Current Order</td>
<td>Section Name</td>
<td>Desired Order</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> 1 2 3 </td>
</tr>
<tr>
<td>1</td>
<td>abc</td>
<td>
<input type='radio' value='1' name='R1' ID='Radio1'>
<input type='radio' value='2' name='R1' ID='Radio2'>
<input type='radio' value='3' name='R1' ID='Radio3'>
</td>
</tr>
<tr>
<td>2</td>
<td>pqr</td>
<td>
<input type='radio' value='1' name='R2' ID='Radio4'>
<input type='radio' value='2' name='R2' ID='Radio5'>
<input type='radio' value='3' name='R2' ID='Radio6'>
</td>
</tr>
<tr>
<td>3</td>
<td>xyz</td>
<td>
<input type='radio' value='1' name='R3' ID='Radio7'>
<input type='radio' value='2' name='R3' ID='Radio8'>
<input type='radio' value='3' name='R3' ID='Radio9'>
</td>
</tr>
<tr>
<td colspan='3'><input type='submit' value='Update Section Order' name='Save'></td>
</tr>
</table>
</Form>
The first part of the javascript validation code is to check if atleast one button in every radio group is checked. This works fine.
The second part in the javascript (highlighted in red) is to make sure that only one radio button is checked in each radio group having the same order( or value). (i.e., if Radio group R1 is checked and has a value of 2, then R2 and R3 should not have any radio button checked with value =2.I am having a problem validating this . Please remember that the number of records to be rearranged is dynamic but will always have the same number of radio buttons across rows and columns.
Any help will be greatly appreciated.
Thank you.
PKS.