Forms and HTML validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yandr

    Forms and HTML validation

    I am sure the answer is somewhere, but although I have searched for it I
    couldn't find it.

    I am doing form validation and I am checking each field using
    document.FormNa me.FieldName.va lue
    My problem is that I am using HTML 4 transitional and if I give a name to
    the form (<form name="something ">) it will not validate. I also can't use
    document.Forms[0].FieldName because I have multiple forms in each page.
    The ID tag doesn't seem to work either (I mean just replace 'name' with
    'id').

    So, the question is how can I access the form and validate at the same time?
    It would be best if someone can direct me to a tutorial that included
    cross-browser compatibility (supporting DOM3 and previous versions).

    Thank you very much in advance and sorry if this is stupid.


  • Andrew Urquhart

    #2
    Re: Forms and HTML validation

    *yandr* wrote in comp.lang.javas cript:[color=blue]
    > I am sure the answer is somewhere, but although I have searched for it
    > I couldn't find it.
    >
    > I am doing form validation and I am checking each field using
    > document.FormNa me.FieldName.va lue My problem is that I am using HTML
    > 4 transitional and if I give a name to the form (<form
    > name="something ">) it will not validate.[/color]

    HTML 4.01 addressed that issue (in 1999):

    [color=blue]
    > I also can't use document.Forms[0].FieldName because I have multiple
    > forms in each page.[/color]

    document.forms["myFormName "].elements["myFieldNam e"].value
    [color=blue]
    > The ID tag doesn't seem to work either (I mean just replace 'name'
    > with 'id').[/color]

    Use of ids for form referencing is not backwards compatible, but to get
    a handle on the form:
    document.getEle mentById("myFor mId")
    [color=blue]
    > So, the question is how can I access the form and validate at the same
    > time?[/color]

    Use the amended 4.01 DTD. A list of current DTDs can be found at:


    Best,
    --
    Andrew Urquhart
    - FAQ: http://www.jibbering.com/faq/
    - Archive: http://groups.google.com/groups?grou...ang.javascript
    - Contact me: http://andrewu.co.uk/contact/

    Comment

    • Michael Winter

      #3
      Re: Forms and HTML validation

      On Tue, 21 Sep 2004 10:09:53 GMT, Andrew Urquhart
      <useWebsiteInSi gnatureToReply@ com.invalid> wrote:

      [snip]
      [color=blue]
      > Use of ids for form referencing is not backwards compatible, but to get
      > a handle on the form:
      > document.getEle mentById("myFor mId")[/color]

      Though the forms collection works just as well except, as you say, with
      old browsers. Then only named forms can be accessed.

      [snip]

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      Working...