Script to warn if all text fields are empty on a form? : Javascript
This is a discussion on Script to warn if all text fields are empty on a form? within the Javascript forums in Programming Languages category; Hello, I need to write a piece of Javascript to determine if *all* text fields on a form are empty. I know how to do this when each text field has a fixed name. Problem is, each one has a dynamically assigned name. I simply need to check if *all* boxes are empty. There is usually 10-20 boxes on my form and I want the user to be able to submit the form if they enter values into at least one text field, but not if they enter nothing. How do I do this? Thanks, Lee...
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I need to write a piece of Javascript to determine if *all* text fields on a form are empty. I know how to do this when each text field has a fixed name. Problem is, each one has a dynamically assigned name. I simply need to check if *all* boxes are empty. There is usually 10-20 boxes on my form and I want the user to be able to submit the form if they enter values into at least one text field, but not if they enter nothing. How do I do this? Thanks, Lee |
|
#2
| |||
| |||
| wrote on 02 jul 2003 in comp.lang.java.javascript: > Hello, > > I need to write a piece of Javascript to determine if *all* text > fields on a form are empty. > > I know how to do this when each text field has a fixed name. Problem > is, each one has a dynamically assigned name. > > I simply need to check if *all* boxes are empty. There is usually > 10-20 boxes on my form and I want the user to be able to submit the > form if they enter values into at least one text field, but not if > they enter nothing. l=(""+ document.myForm.myField1.value+ document.myForm.myField2.value+ document.myForm.myField3.value+ document.myForm.myField4.value+ document.myForm.myField5.value) if(l.length>0) {alert("Not all empty")} else {alert("All empty")} -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) |
|
#3
| |||
| |||
| On 02 Jul 2003 14:45:29 GMT, "Evertjan." <exjxw.hannivoort@interxnl.net> wrote: >l=(""+ >document.myForm.myField1.value+ >document.myForm.myField2.value+ >document.myForm.myField3.value+ >document.myForm.myField4.value+ >document.myForm.myField5.value) > >if(l.length>0) > {alert("Not all empty")} >else > {alert("All empty")} That won't work because the number of the next boxes is dynamic. There could be 5, there could be 50. I said there is usually 10-20 but this changes. Any ideas? |
|
#4
| |||
| |||
| wrote on 02 jul 2003 in comp.lang.java.javascript: > On 02 Jul 2003 14:45:29 GMT, "Evertjan." > <exjxw.hannivoort@interxnl.net> wrote: > >>l=(""+ >>document.myForm.myField1.value+ >>document.myForm.myField2.value+ >>document.myForm.myField3.value+ >>document.myForm.myField4.value+ >>document.myForm.myField5.value) >> >>if(l.length>0) >> {alert("Not all empty")} >>else >> {alert("All empty")} > > That won't work because the number of the next boxes is dynamic. There > could be 5, there could be 50. I said there is usually 10-20 but this > changes. Yes it would work, because I did not intend to give you a finished programme, but to show you that making one long string and testing it for a length > 0 If you make the number of inputs dynamic, there is no reason not to make the javascript dynamic too. To help you on your way: l="" for(i=1;i<imax;i++) l+=document.myForm['myField'+i].value or perhaps something like: l="" for(i in document.myForm.myFields) l+=document.myForm.myFields[i].value or counting on another level n=0 for(i in document.myForm.myFields) n+=document.myForm.myFields[i].value.length not tested, you have to work on it. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| no empty form fields after submitting form | usenet | PHP | 25 | 09-22-2007 08:57 AM |
| Validating form fields aren't empty | usenet | Javascript | 4 | 04-15-2007 07:27 PM |
| Pro 7.0.8 won't save text in form fields | usenet | Adobe Acrobat | 1 | 03-07-2007 04:31 AM |
| Problem passing empty form fields to access parameter query | usenet | Inetserver | 2 | 01-29-2007 05:09 PM |
| Empty Form Fields After Save | usenet | Adobe Acrobat | 0 | 12-17-2006 09:39 PM |
All times are GMT -5. The time now is 08:43 AM.


