How to validate multiple radio buttons...(JS)

Hai all

  i have a problem on validating multiple radio buttons.

iam doing an online quiz in Notes. the administration is completely in notes. only the test taking part is in web. so after the user had chosen the choices i have to transfer the results to notes.

the problem iam facing is validating multiple radio buttons.

the requirement is as follows :

i have 4 radio button groups and a submit botton as shown below :

  1. is this nice ?

yesNo


2.<when was java founded ?

198719902000


  1. is it true or false ?

truefalse


  1. find the odd man out ?

robustportablereliablecongesant


submit


now remember the no of radio groups can be any number. say it can be 10 or 20 or 50 etc. so i have to construct a loop to process the radio buttons of any number.(10 or 20 or 50 )

now the code i have is as follows

function dumpvalues(){

var i, j, radio_set,chkdval,txtare;

i = 0;

while(i < document.forms[0].elements.length) {

if(document.forms[0].elements[i].type == 'radio') {

    radio_set = eval('document.forms[0].' + document.forms[0].elements[i].id);

    for(j = 0; j < radio_set.length; j++) {

        if(radio_set[j].checked) {

            chkdval=(radio_set[j].value);

	alert(chkdval);

	document.forms[0].Answers.value+=chkdval+"~"



        } // 2nd if closed

        i++;

    } // for loop closed

if(!chkdval){

alert(“you have missed out a selection”);

} //3rd if closed

} // 1st if closed

else {

    i++;

} //1st else closed

} //while loop closed

} //function closed

now the above code checks for radio buttons and if the radio button is selected then it gives a prompt message of the value chosen. and adds the value in a text field called “Answers”.

now my requirement is:

i have a text field named “Answers”. and if any radio button is chosen then i want to put the chosen value into the text field.

if no radio button is chosen then i want to add a predefined value for eg say “N/A” to the text field.

to be more brief:

i want to walk through each radio group and i should find out whether it is checked or not and if not i should add a value say “N/A” to the text field and if any radio group is checked then i should add the chosen value to the text field.

The problem in the above code is it is not Modular. ie if any one radio button in the first radio group is checked then

it shows the chosen value.

and if second group is left unchecked and if you check any one of the third radio group. the code should actually prompt that you missed second radio group. but the code dosn’t do so !

any help on this will be much appreciated.

thanks and regards

VJ…

Subject: how to validate multiple radio buttons…(JS)

Try to use this below code…i think it will help you.

------------------ CODE START --------------------

  1. is this nice ?

yes

No


2.when was java founded ?

1987

1990

2000


  1. is it true or false ?

true

false


  1. find the odd man out ?

robust

portable

reliable

congesant







------------------ CODE END -----------------------

Subject: RE: how to validate multiple radio buttons…(JS)

Thanks very much Sandip for you timely help.

i ve got throught it…

VJ…