dynamic radio button validation problems
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, November 16, 2003 07:50 PM

Hi. I have a jsp that asks a user to answer. "Do you agree?" followed by 2 radio buttons. There is one for "yes" and one for "no". The page is dynamic and the question can be asked repeatedly. I'm having trouble picking a dynamic naming convention for the form radio buttons, so that each set of yes-no radio buttons is considered individually. I'd like to use JavaScript to validate that either "yes" or "no" has been selected for each set. Next, if neither button has been selected I'd like to prompt the user with an alert message and stop page processing. Finally I want to disable text and select fields from the same form if "No" is selected.    More>>

Hi. I have a jsp that asks a user to answer. "Do you agree?" followed by 2 radio buttons. There is one for "yes" and one for "no".


The page is dynamic and the question can be asked repeatedly.


I'm having trouble picking a dynamic naming convention for the form radio buttons, so that each set of yes-no radio buttons is considered individually. I'd like to use JavaScript to validate that either "yes" or "no" has been selected for each set.

Next, if neither button has been selected I'd like to prompt the user with an alert message and stop page processing.

Finally I want to disable text and select fields from the same form if "No" is selected.


I'm currently having an awful time trying to do this. The radio button value isn't being found and the form continues to submit even when a radio button isn't selected.


Any guidance and help would be greatly appreciated.

Thank you.

Sincerely,

Tiffany

   <<Less

Re: dynamic radio button validation problems

Posted By:   Firat_Tiryaki  
Posted On:   Monday, November 17, 2003 02:18 AM

you can refer to a radio checked property like below


document.formName.radioName[0].checked -> it returns boolean, so you have to check two options in your code



document.formName.yesNoRadio[0].checked -> this is for No maybe


document.formName.yesNoRadio[1].checked -> this is for Yes maybe



And to disable all the elements in a form



for (i=0;i if(document.formName.elements[i].name!="yesNoRadio"){
document.formName.elements[i].disabled=true;
}
}
About | Sitemap | Contact