0

In my javascript book, there is this code:

form.action="echo.pl"
form.method="POST"

The book describes these two lines of code as

statements to specify a submission method and a server-side script to process the form.

But I have no idea what they are talking about. This code is part of a larger code that first assigns form values, then runs the server-side script response echo the submitted name=value pairs assigned by the script. Since there is no proper explanation, I am unable to understand what it means.

dotmax
  • 21
  • 2
  • 4
  • I am not sure if the question is about *HTML form/submission in general* or the *lines of code posted* .. –  Jul 17 '12 at 04:47
  • I suggest finding (e.g., via Google) a tutorial about how HTML forms work. If you're going to be looking at JS code that manipulates forms it's good to understand how forms work _without_ JS... – nnnnnn Jul 17 '12 at 05:39

2 Answers2

2

A HTML form is a way of submitting user data to the server. But to submit data, there are a couple of questions:

  • Which part of server (sort of) to submit to? (ie, which script/program will handle the submitted data). This is best represented by the URL to the resource.
  • How should the data be submitted? There are various HTTP methods -- GET/POST/PUT/DELETE/ etc etc ..

The answer lies in the form tag's attribute:

<form method="<METHOD OF SUBMIT: GET/POST>" action="<WHERE TO SUBMIT?: URL OF SCRIPT" ..>

In your code, form is a reference to the form, and when you say:

  • form.action: You modify the URL to submit to.
  • form.method: You modify the HTTP method to use to submit.
UltraInstinct
  • 43,308
  • 12
  • 81
  • 104
0

You need to have a page that will handle the form's data when the user submits it. The form's action attribute is the page it will send data to using the method described in its method attribute. See this question for difference between GET and POST.

From w3:

action      %URI;          #REQUIRED -- server-side form handler --
method      (GET|POST)     GET       -- HTTP method used to submit the form--
Community
  • 1
  • 1
sachleen
  • 30,730
  • 8
  • 78
  • 73