I have a form that has 10 fields on it. I have made all of them "Required".
I also am using vb if statements to decide whether or not each field should
be on the page. I am using the vb to compare values in my database and if a
certain field equals something then the field is shown on the form. When
the form is displayed in the browser, it could any increment of the 10
fields on it. My problem is that unless all fields are being shown then the
validation does not work and the form submits even with blank fields. Has
anyone tackled this kind of a situation before and if so how did they
accomplish it? Thanks in advance for your help!
Darren
|
|
0
|
|
|
|
Reply
|
Darren
|
5/24/2005 4:50:26 PM |
|
Use Javascript, it's better than VBScript.
Or go to alt.comp.lang.vbscript
|
|
0
|
|
|
|
Reply
|
DJ
|
5/24/2005 5:23:03 PM
|
|
"DJ Craig" <spit@djtricities.com> wrote in message
news:1116955383.938508.23190@g43g2000cwa.googlegroups.com...
> Use Javascript, it's better than VBScript.
> Or go to alt.comp.lang.vbscript
>
I think that I explained this wrong in my first post. I am using javascript
to validate the forms and asp if statements to decide which form show on the
page. The problem it that the javascript is not working unless all of the
form fields are visible on the page.
|
|
0
|
|
|
|
Reply
|
Darren
|
5/24/2005 7:09:41 PM
|
|
In article <1d354$42935aca$d8cc6cea$27572@LIGHTSHIP.NET>, news@lan-
specialist.com enlightened us with...
> I have a form that has 10 fields on it. I have made all of them "Required".
Meaning what?
ASP.NET?
> I also am using vb if statements to decide whether or not each field should
> be on the page.
The browser doesn't see server-side code.
> I am using the vb to compare values in my database and if a
> certain field equals something then the field is shown on the form. When
> the form is displayed in the browser, it could any increment of the 10
> fields on it. My problem is that unless all fields are being shown then the
> validation does not work and the form submits even with blank fields. Has
> anyone tackled this kind of a situation before and if so how did they
> accomplish it? Thanks in advance for your help!
Which runs on the server, and which the client?
This group is for javascript. If the problem is with the VB on the server,
posting here doesn't help much unless one of us who knows VB decides to go
ahead and answer an OT question.
Post your .NET code and I'll check it out.
Providing a URL so I can see what the browser gets is also helpful.
--
--
~kaeli~
Contrary to popular opinion, the plural of 'anecdote' is
not 'fact'.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
|
|
0
|
|
|
|
Reply
|
kaeli
|
5/24/2005 8:13:24 PM
|
|
Without a little more information, it's hard to understand where your
problem might be.
Here's my understanding:
Your ASP is conditionally outputting form fields. In many cases, a form
field simply won't exist in the HTML that is being output.
Your JavaScript form validation is broken-- it will only validate
properly if ALL fields exist on the page, which is rarely the case.
If this is correct, you need to add to your validation a check to see
if the element exists. If it does, validate its value. If it does not,
skip it and/or consider it valid.
This check is fairly simple since JavaScript is so tolerant. If an
element exists, it evaluates to true. If it does not, it will not.
if( document.forms[ myForm ].elements[ myElement ] )
validate( myElement );
Darren wrote:
> "DJ Craig" <spit@djtricities.com> wrote in message
> news:1116955383.938508.23190@g43g2000cwa.googlegroups.com...
> > Use Javascript, it's better than VBScript.
> > Or go to alt.comp.lang.vbscript
> >
>
> I think that I explained this wrong in my first post. I am using javascript
> to validate the forms and asp if statements to decide which form show on the
> page. The problem it that the javascript is not working unless all of the
> form fields are visible on the page.
|
|
0
|
|
|
|
Reply
|
Random
|
5/24/2005 9:13:30 PM
|
|
Darren wrote:
> "DJ Craig" <spit@djtricities.com> wrote in message
> news:1116955383.938508.23190@g43g2000cwa.googlegroups.com...
>
>>Use Javascript, it's better than VBScript.
>>Or go to alt.comp.lang.vbscript
>>
>
>
> I think that I explained this wrong in my first post. I am using javascript
> to validate the forms and asp if statements to decide which form show on the
> page. The problem it that the javascript is not working unless all of the
> form fields are visible on the page.
>
>
Form validation is usually done from the form onsubmit event:
<form ... onsubmit="return validateForm(this);" ...>
The validateForm() function tests whatever, then returns true or false
depending on the success or failure of the validation. If false is
returned, the form won't be submitted (at least, that's the theory).
Please remember that the fact that your forum subsequently submits does
not mean it actually passed validation, you can't guarantee that at
all. The user may have JavaScript disabled or may have bypassed your
validation routine some other way. Check everything again on the
server.
Your validateForm() function may go something like:
function validateForm(f){
var formElements = f.elements;
var formValid = true;
var i = 0;
if ( formElements[i] ){
var el = formElements[i];
do {
if ( 'someElementName' == el.name ) {
/* do validation for this element, if it fails:
*
* formValid = false;
*
*/
}
if ( 'anotherElementName' == el.name ) {
/* do validation for this element, if it fails:
*
* formValid = false;
*
*/
}
} while ( (el = formElements[++i]) )
}
return formValid;
}
You may wish to use 'switch' (JavaScript's version of 'case') instead
of if's, that's up to you. It is also handy to base your 'if' on the
className, say if you have lots of text fields that you just want to
check that they have something in them:
if ( 'plainText' == el.className && '' == el.value ) {
formValid = false;
}
In your HTML:
<input type="text" class="plainText" ... >
The className 'plainText' doesn't have to be defined anywhere, just set
on the element. You can cope with multiple class names too, it just
takes a little more effort (and is a tad slower also):
if ( /\bplainText\b/.test(el.className) && '' == el.value ) {
formValid = false;
}
Have fun.
--
Rob
|
|
0
|
|
|
|
Reply
|
RobG
|
5/25/2005 12:13:32 AM
|
|
Yes, VBS is only for Internet Explorer browser and in windows 32bit
platforms, so, won't work in say macOS IE, whereas javascript will do fine
in any browser/platform. What you need is select this or that element and
then more options are shown, that were not there Unless you do
choose/select/tick/check/uncheck/else that element, very easily done in js
by using the objects style stack, if (SOANDSOHAPPENS)
{ obj.style.display='none'} else { obj.style.display='inline' /// or
'block' whicheve the box happens to be}. Peruse around at
http://www.javascriptkit.com/cutpastejava.shtml .
Danny
On Tue, 24 May 2005 09:50:26 -0700, Darren <news@lan-specialist.com> wrote:
> I have a form that has 10 fields on it. I have made all of them
> "Required".
> I also am using vb if statements to decide whether or not each field
> should
> be on the page. I am using the vb to compare values in my database and
> if a
> certain field equals something then the field is shown on the form. When
> the form is displayed in the browser, it could any increment of the 10
> fields on it. My problem is that unless all fields are being shown then
> the
> validation does not work and the form submits even with blank fields.
> Has
> anyone tackled this kind of a situation before and if so how did they
> accomplish it? Thanks in advance for your help!
>
> Darren
>
>
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
0
|
|
|
|
Reply
|
Danny
|
5/29/2005 1:56:54 AM
|
|
|
6 Replies
101 Views
(page loaded in 0.111 seconds)
Similiar Articles: Validate form for 4-digit integer - comp.lang.javascript ...Phone Number Validation using JavaScript: International Phone ... International Phone Number Validation in Forms . In forms when asking for phone numbers fields it is a ... Validation for unicode alphanumeric characters? - comp.lang ...Hi, I am looking for some form of validation for all the alphanumeric characters in the entire unicode range e.g. the validation should also accept j... submit form, validate form, set cookie, send email, download file ...Looking for an email/website validator, FM7 - comp.databases ... submit form, validate form, set cookie, send email, download file ... submit form, validate form, set ... E-mail Validation - comp.databases.filemakersubmit form, validate form, set cookie, send email, download file ... submit form, validate form, set cookie, send email, download file ... submit form, validate form ... disabling field validation - comp.databases.filemakerValidate form for 4-digit integer - comp.lang.javascript ... disabling field validation - comp.databases.filemaker Validate form for 4-digit integer - comp.lang.javascript ... Can't get line breaks into email message body - comp.lang ...... form> No client-side scripting will be required then, although you could use the `onsubmit' intrinsic event handler attribute to provide for client-side form validation ... html form change Input value based on drop-down selected - comp ...I have an HTML Form below that has a drop-down box where the user selects "Monthly ... By "valid HTML" I mean a document which passes the W3C HTML validator: <http ... Importing data into Adobe XML (Designer 6) or Acrobat Forms - comp ...Designer (XML) Forms advantages: Precise control of location, fonts, etc. Sophistticated validation, patterns Designer Forms disadvantages: No easy merge with XFDF ... Go to portal row -- dialog?? - comp.databases.filemakerHi; I am trying to build a data entry form using FM7 Developer on Windows XP to ... Go to portal row -- dialog?? - comp.databases.filemaker disabling field validation ... Korean chars on javascript alerts - comp.lang.javascript ...Validation for unicode alphanumeric characters? - comp.lang ... Hi, I am looking for some form of validation for all the alphanumeric characters in ... comp.lang ... JavaScript Form ValidationE-mail Validation. The function below checks if the content has the general syntax of an email. This means that the input data must contain an @ sign and at least one ... JavaScript Form Validation : quick and easy!Add validations quickly to your form using this simple, easy to use, free form validation script. 7/27/2012 10:51:51 AM
|