Hi I had the folloiwng problem

have two tables on web page R and S and a javascript array jsR AND jsS which gives
the relationship between R and S

Both Table R and S have two columns...one for checkbox and other Names

Table R Table S

ChkBoxR Rname ChkBoxS Sname

x R1 x S1
x R2 x S2

.....

X--> represents Checkbox

There can be m rows for Table R and n Rows for Table S
The Page also has Submit button


js Array RS
=========
Gives relation between R and S

var jsR = {R1,R2,A,B...}
Var jsS = {S1,S2,D,E....}


above indicates R1 is related S1,R2 is related to S2...



I have specified following Conditions for first two elements same is also valid for all of them

ChkBox Result
========================================================================
1> If R1 and R2 checked and no s1/s2 give alert Click something from S
checked and submit button clicked
2> If s1 and s2 checked and no R1/R2 give alert Click something from R
checked and submit button clicked
3> If R1 and S1 checked or give alert R1 related to S1
S1 and R1 checked in any order (on click of checkbox)
(refer javascript jsR and jsS array)
4> If R2 and S1 checked or give alert Sucess
S1 checked and R2 checked (on click of checkbox)
(refer javascript jsR and jsS array)

Condition 1 and 2 will be checked only on Submit button clicked

User can check any checkbox/checkboxes in any order . the relation should be determined only
on checkbox click at runtime ie Multiple R's and be Related to multiple S and relation betn R and S would be determined using the js Array. in otherwords the above will case will have m x n possibilities


Script:

<script>
var jsR = ["R1","R2"];
var jsS = ["S1","S2"];
function checkForm(theForm)
{

var el = theForm.elements;

if((el[jsR[0]].checked && el[jsR[1]].checked) && (!el[jsS[0]].checked || !el[jsS[1]].checked))
{
alert("give alert Click something from S");
}
if((el[jsS[0]].checked && el[jsS[1]].checked) && (!el[jsR[0]].checked || !el[jsR[1]].checked))
{
alert("give alert Click something from R");
}


return false;
}
function chck(obj)
{
var el = obj.form.elements;
var le = obj.name.substring(0,1);
var nm = obj.name.substring(obj.name.length-1,obj.name.length);
if(obj.checked)
{
if(le=="R")
{
if(el[jsS[nm-1]].checked)
{
alert("S"+nm+" related to R"+nm+"");
}
if(el[jsS[(nm-1==0?1:0)]].checked)
{
alert("Sucess");
}
}
if(le=="S")
{
if(el[jsR[nm-1]].checked)
{
alert("R"+nm+" related to S"+nm+"");
}
if(el[jsR[(nm-1==0?1:0)]].checked)
{
alert("Sucess");
}
}

}
}
</script>

<form onsubmit="return checkForm(this)">


<table cellspacing=0 cellpadding=0 border=1>
<tr><td>R1</td><td><input onclick=chck(this) type=checkbox name=R1 value=RRRR1></td></tr>
<tr><td>R2</td><td><input onclick=chck(this) type=checkbox name=R2 value=RRRR2></td></tr>
</table>
<br><br>
<table cellspacing=0 cellpadding=0 border=1>
<tr><td>S1</td><td><input onclick=chck(this) type=checkbox name=S1 value=SSSS1></td></tr>
<tr><td>S2</td><td><input onclick=chck(this) type=checkbox name=S2 value=SSSS2></td></tr>
</table>
<br>
<input type=submit>
</form>

Can the checkForm() function be written such to be dynamic to check "n" number of conditions and give an alert when any "RName" is/are related to "Sname