• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to check if user has inputed all the fields in a form?

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all:
Can someone please teach me the Javascript for the following story?
I generate a JSP page which contains one form in it. The total number of the radio boxes and the names of the radio boxes are generated dynamically by JSP, so Java Script can not call one radio box directly.
When the user submits the form, I want my JavaScript to check for all the inputs, if one input in the form is null, then it returns an error.
How to do this by JavaScript? I have the form name, but what collections or methods or I use?
Thanks!
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Stephen,
First when you load radio boxes dynamicall by jsp atleast checked one as default...
try following code..in Javascript
function check() {
var valid=false;
j=0;
for(i=0; i< document.formname.length; i++) {
e = document.formname.elements[i];
if (e.type=='checkbox' && e.checked) {
j++;
}//end of if
}//end of for
if (j==0) {
alert("Select a box before submitting this form");
return valid = false;
}//end of if
}//end of function check
First write form name...in html or along with jsp also.
then generet radios by jsp..
and write script in heah tag.
Best Wishes.
S. Oza
 
reply
    Bookmark Topic Watch Topic
  • New Topic