www.webdeveloper.com
Results 1 to 7 of 7

Thread: Referencing a form field text value

  1. #1
    Join Date
    Mar 2004
    Posts
    2

    Referencing a form field text value

    I am using FrontPage 2002 but am coding the Javascript by hand. Within a form I request a password twice and wish to verify that they are the same

    Form Name = registration
    Field Name = password (password attribute set)

    Within the form "123" is input into the field named password

    A function is accessed by onClick on the Submit button

    After executing the following statement
    msg = registration.password.value
    msg is undefined.

    However if I step through using the debugger msg will show a value of 123

    The same occurs if I try to store registration.password.length in a variable

    Thoughts anyone?
    Thank you

  2. #2
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    700
    A couple of things to try...

    First, define your variable msg somewhere outside the function.

    Example...

    In your header,

    <script language="javascript">
    msg = "";
    function validate()
    {
    //your password validation code
    }
    </script>

    If that doesn't work, try accessing the value this way...
    msg = document.registration["password"].value

    Cheers
    CTB
    Oh Lord, please help me be the person my dog thinks I am.

  3. #3
    Join Date
    Jun 2003
    Location
    The United States Site: http://kellyj.t35.com
    Posts
    2,561
    or <<<document.getElementsByName('password')[0].value>>>. That should be more compatible and browser friendly.

    Try alerting the contents of msg right after retrieving it. Alsom if it is a submit button, place the triggered function in an event-driven attribute, onSubmit, of the form.
    Code:
    <form onSubmit="whatever is in the onclick on the submit">
      <input type="submit" onclick="do not put anything here">
    </form>

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    document.forms['form_name'.elements['field_name'.value

    should never get failed...

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I mixed the brackets...:

    document.forms['form_name'].elements['field_name'].value

  6. #6
    Join Date
    Mar 2004
    Posts
    2
    Thank you chestertb, steelersfan88 and kor for trying to help me. It was much appreciated.

    In hindsight, much to my chagrin, I may not have reported what turned out to be a critical piece of information.

    To recap:
    Using FrontPage 2002
    Form Name: registration
    Field name: password
    Specifying constraints within FP2002 on the field.

    This latter point is critical. For those that do not already know it FP2002 fills a form with so called "web-bots" to handle field verification etc. These web-bots are expanded into Javascript code as part of the "publishing" process. If you are using FP to do any field validation it will IGNORE the frame name you supplied within FP itself and will use FrontPage_Form1 as the frame name.

    Another point which may be of interest. If you use, as was suggested, a function within onSubmit instead of onClick (on the Submit button) it MUST be called FrontPage_Form1_Validator

    Finally while there may be other ways of doing it, because I wanted to add another check above those provided by FP validation I did the following:
    1) Within the Form Field properties I set all my validation.
    2) I published the page.
    3) I accessed the page through my browser, selected view source, and "copied" all the JavaScript FP supplied to do the validation.
    4) I then removed all the field vaildations with FP, pasted in the code it had generated when the validations were in place, added my additional code and then republished the page.

    If any of this does not make sense or you want additional explanations please feel free to say so
    Regards
    Abominable

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    eeeerrr... Front Page code lines are different of and are not standard DHTML or DOM code lines, so... You have to decide, or one or another... If Front Page, well... hm, you will have to find someone who work with..., not sure here are too many.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles