• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

problem in validating multiple radioboxes in JS

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,

I am writing a simple online quiz application in struts .I take answers from users in radio boxes.There is a client side validation in JS to prompt the user in case he/she leaves any question unanswered.The problem is the form is getting submitted as soon as it enters the JS from my JSP. In my jsp i loop through the beans to get options entered for each of the question.In my jsp i have commented in the line where the problem lies.Kindly help me to get a solution.

below is my jsp snippet

Regards,
Rajagopal
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us what the serverside code renders as. Showing us serverside code does not help since we do not know what it looks like to the JavaScript.
 
S Rajagopal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric i was looking to figure out a way to overcome my javascript error.The serverside doesnt make any difference it is working fine.I have now fixed the javscript to validate multiple radio boxes that is better than my previous code.Thanks Eric.
function validation(form)
{

var num,i,j;
var question=15;
var group;
var blankquestion=new Array();
var toadd="please enter answers for";

var arr = new Array(15)

for (i=1; i<=15; i++)
arr[i]=new Array(4)


for(i=1;i<=15;i++)
{
for(j=0;j<4;j++)
{
arr[i][j] = document.getElementsByName('question'+i).item(j);


}
}



var empty;
for(i=1;i<=15;i++)
{
empty=0;
for(j=0;j<4;j++)
{
if(arr[i][j].checked==false)
{
empty++;
if(empty==4)
{
blankquestion.push(arr[i][j].name);
alert(arr[i][j].name);
}

}
}
}
if( blankquestion.length>0)
{
for(var l=0;l<blankquestion.length;l++)
{
toadd=toadd+" "+blankquestion[l];



}
alert(toadd);
}
else
{
alert("all answered");
return true;
}

return false;




}
 
Sheriff
Posts: 67553
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic