trouble calling a function to validate form input

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

    trouble calling a function to validate form input

    i'm trying to pass a form object to a function to validate the forms user
    input
    when i try to access a forms properties-like .elements[x] there is no
    response from the function and no error msg, i get a screen flash
    and
    if i try to preset an element property before calling the function like:
    this.firstName. optional=true;
    the code after that doesn't get executed
    going bananas, please help

    to successfully call the function:
    <input type="button" value="Submit Volunteer Information"
    onclick="
    alert('this message at start of onclick');
    verify(this);">

    the called function:
    function verify(f) {
    alert('now entering verify function');
    var msg1 = "the current message is = " ;
    var e = f.elements[0];
    msg1 += e.type;
    alert(msg1);
    return false;
    }
    so...... i get the first alert, then nothing????

    and while on the subject this code does not even get as far as the 2nd
    alert:
    <input type="button" value="Submit Volunteer Information"
    onclick="
    alert('this message at start of onclick');
    this.firstName. optional=true;
    alert('this message after optional assignment');
    verify(this);">


  • Lee

    #2
    Re: trouble calling a function to validate form input

    "bbxrider" said:[color=blue]
    >
    >i'm trying to pass a form object
    >...[/color]
    [color=blue]
    ><input type="button" value="Submit Volunteer Information"
    >onclick="
    >alert('this message at start of onclick');
    >this.firstName .optional=true;
    >alert('this message after optional assignment');
    >verify(this);" >[/color]

    In the context of an onClick handler, "this" refers to the
    form element, not the form. Since each element has an
    attribute named "form", which is a reference to its parent
    form, you want to use: "verify(this.fo rm)".

    Comment

    • bbxrider

      #3
      Re: trouble calling a function to validate form input

      thanks for the help, that works, and found as well, to set an attribute of a
      field, like .optional
      that needs this.form as well.
      i've searched high and low to find lists of properties and methods for .form
      and nothing is showing up
      in google groups, any suggestions where to find that documentation? and not
      just for .form but all the
      objects in html objects

      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:bg754t01kb d@drn.newsguy.c om...[color=blue]
      > "bbxrider" said:[color=green]
      > >
      > >i'm trying to pass a form object
      > >...[/color]
      >[color=green]
      > ><input type="button" value="Submit Volunteer Information"
      > >onclick="
      > >alert('this message at start of onclick');
      > >this.firstName .optional=true;
      > >alert('this message after optional assignment');
      > >verify(this);" >[/color]
      >
      > In the context of an onClick handler, "this" refers to the
      > form element, not the form. Since each element has an
      > attribute named "form", which is a reference to its parent
      > form, you want to use: "verify(this.fo rm)".
      >[/color]


      Comment

      Working...