www.webdeveloper.com
Results 1 to 2 of 2

Thread: example from w3c

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    example from w3c

    hello,

    I am learning Javascript with the material on the w3schools website and I cannot understand somehing in the explanation of the onsubmit event (to be found here)
    I don't get why they use the
    action="submit.htm"
    in the form frm1 and why there isn't a simple html button that executes their greeting() function.
    On top of this, I don't understand why in the alert box, their Javascript "command" is
    document.forms["frm1"]["fname"].value
    and not
    document.frm1.fname.value

    I read and re-read the code and searched but I cannot figure out answers to these (basic) questions.
    Thank you in advance for any kind of explanation.

    cheers

  2. #2
    Join Date
    Jun 2007
    Location
    Washington D.C. Metro
    Posts
    76
    I don't get why they use the
    action="submit.htm"
    in the form frm1 and why there isn't a simple html button that executes their greeting() function.
    The form action and the greeting function are two separate things. The form action tells where the form values are going to be submitted, so the sequence of events is 1) click the submit button, 2) greeting message pops up, 3) arrive at new page (submit.htm) with form values in HTTPPOST array for processing. OnSubmit is useful in, for example, client-side validation where you have to check that the form field values are valid before you allow them to be submitted.

    I don't understand why in the alert box, their Javascript "command" is
    document.forms["frm1"]["fname"].value
    and not
    document.frm1.fname.value
    document.forms is an associative array or object that contains all of the form information on a page. Any specific form name is a key in this array. Another way to write it is:

    document.forms.frm1.fname.value

    I think you can actually do it your way but it isn't regular javascript syntax so it is avoided (especially by w3c):

    document.frm1.fname.value

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