Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Horizontal Radio Group

Status
Not open for further replies.

venur

MIS
Aug 26, 2003
418
US
Hi,

The page has multipule radio groups and if one of the radio button in the group is clicked to "Yes" then all the "No" needs to be checked for the selected id, but not the clicked indexed id;

Below is the code, may be i am clear with my question
Code:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
 function test(id, idx){
   
   var array = document.all.namedItem(id);
   alert(" Id Name is : " + id + "\n Selected Index of the id is : " + idx + "\n Length of array is : " + array.length);
   for(var i=0; i < array.length; i++){
    var obj = array[i];
    if(idx != i){
		if(obj.type == 'radio'){
		  obj.checked = true;
		 }
	 }
   }
 }
//-->
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="">
1<INPUT TYPE="radio" NAME="1" value="Y" onClick="test('one', '0')" id="one"> Yes
 <INPUT TYPE="radio" NAME="1" value="N" onClick="test('one', '0')" id="one"> No
<BR>
1<INPUT TYPE="radio" NAME="2" value="Y" onClick="test('one', '1')" id="one"> Yes
 <INPUT TYPE="radio" NAME="2" value="N" onClick="test('one', '1')" id="one"> No
<BR>
3<INPUT TYPE="radio" NAME="3" value="Y" onClick="test('three', '2')" id="three"> Yes
 <INPUT TYPE="radio" NAME="3" value="N" onClick="test('three', '2')" id="three"> No
<BR>
1<INPUT TYPE="radio" NAME="4" value="Y" onClick="test('one', '3')" id="one"> Yes
 <INPUT TYPE="radio" NAME="4" value="N" onClick="test('one', '3')" id="one"> No
<BR>
1<INPUT TYPE="radio" NAME="5" value="Y" onClick="test('one', '4')" id="one"> Yes
 <INPUT TYPE="radio" NAME="5" value="N" onClick="test('one', '4')" id="one"> No
<BR>
3<INPUT TYPE="radio" NAME="6" value="Y" onClick="test('three', '5')" id="three"> Yes
 <INPUT TYPE="radio" NAME="6" value="N" onClick="test('three', '5')" id="three"> No
<BR>
</FORM>
</BODY>
</HTML>

Thank you,
Venu
 
Hi,

Thank you got it working, but i am sure there might be a better and esay way of this.

Code:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
 function test(id, nam){
   var array = document.all.namedItem(id);
   alert(" Id Name is : " + id + "\n Length of array is : " + array.length +"\n Name is :" + nam);
   for(var i=0; i < array.length; i++){
    var obj = array[i];
    var words = id.split("_");
	 if((words[1] == "y") || (words[1] == "Y")){
	   var obj1 = document.all.namedItem(words[0]+"_n");
	   	  for(var j=0; j< obj1.length; j++){
		   var nObj = obj1[i];
		   if(nObj.name != nam){
			 nObj.checked = true;
			 }
 		 }
	}
    } // end for i
 } // end fun
//-->
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="">
1<INPUT TYPE="radio" NAME="1" value="Y" onClick="test('123_y', this.name)" id="123_y"> Yes
 <INPUT TYPE="radio" NAME="1" value="N" onClick="test('123_n', this.name)" id="123_n"> No
<BR>
1<INPUT TYPE="radio" NAME="2" value="Y" onClick="test('123_y', this.name)" id="123_y"> Yes
 <INPUT TYPE="radio" NAME="2" value="N" onClick="test('123_n', this.name)" id="123_n"> No
<BR>
3<INPUT TYPE="radio" NAME="3" value="Y" onClick="test('three_y', this.name)" id="three_y"> Yes
 <INPUT TYPE="radio" NAME="3" value="N" onClick="test('three_n', this.name)" id="three_n"> No
<BR>
1<INPUT TYPE="radio" NAME="4" value="Y" onClick="test('123_y', this.name)" id="123_y"> Yes
 <INPUT TYPE="radio" NAME="4" value="N" onClick="test('123_n', this.name)" id="123_n"> No
<BR>
1<INPUT TYPE="radio" NAME="5" value="Y" onClick="test('123_y', this.name)" id="123_y"> Yes
 <INPUT TYPE="radio" NAME="5" value="N" onClick="test('123_n', this.name)" id="123_n"> No
<BR>
3<INPUT TYPE="radio" NAME="6" value="Y" onClick="test('three_y', this.name)" id="three_y"> Yes
 <INPUT TYPE="radio" NAME="6" value="N" onClick="test('three_n', this.name)" id="three_n"> No
<BR>
</FORM>
</BODY>
</HTML>

Cheers
Venu
 
Hi,

It would be great if you can suggest me on how to go about this problem.

Thanks
Venu
 
Hi,

No, just an other or alternative way to approch the problem. Trying the other way making ID unique
Code:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
 function test(o){
   //var array = document.all.namedItem(o.id);
   var array = document.forms[0];
   alert(" Id Name is : " + o.id + "\n Length of array is : " + array.length +"\n Name is :" + o.name);
   for(var i=0; i < array.length; i++){
    var obj = array[i];
	 if((obj.type == 'radio') || (obj.type=='RADIO')){
	  //alert(obj.name == o.name);
	  if(obj.name != o.name){
	    var words = o.id.split("_");
		var oWords = obj.id.split("_");
		//alert(words[0] + "==" + oWords[0] + "==" + words[1])
		if((words[0] == oWords[0])){
		  obj.checked = true;
		}
	  }
	}
   } // end for i
 } // end fun
//-->
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="">
1<INPUT TYPE="radio" NAME="1" value="Y" onClick="test(this)" id="123_y_1"> Yes
 <INPUT TYPE="radio" NAME="1" value="N" onClick="test(this)" id="123_n_1"> No
<BR>
1<INPUT TYPE="radio" NAME="2" value="Y" onClick="test(this)" id="123_y_2"> Yes
 <INPUT TYPE="radio" NAME="2" value="N" onClick="test(this)" id="123_n_2"> No
<BR>
3<INPUT TYPE="radio" NAME="3" value="Y" onClick="test(this)" id="three_y_3"> Yes
 <INPUT TYPE="radio" NAME="3" value="N" onClick="test(this)" id="three_n_3"> No
<BR>
1<INPUT TYPE="radio" NAME="4" value="Y" onClick="test(this)" id="123_y_4"> Yes
 <INPUT TYPE="radio" NAME="4" value="N" onClick="test(this)" id="123_n_4"> No
<BR>
1<INPUT TYPE="radio" NAME="5" value="Y" onClick="test(this)" id="123_y_5"> Yes
 <INPUT TYPE="radio" NAME="5" value="N" onClick="test(this)" id="123_n_5"> No
<BR>
3<INPUT TYPE="radio" NAME="6" value="Y" onClick="test(this)" id="three_y_6"> Yes
 <INPUT TYPE="radio" NAME="6" value="N" onClick="test(this)" id="three_n_6"> No
<BR>
</FORM>
</BODY>
</HTML>

Thank you
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top