JavaScript Tutorial/Form/Method

Материал из Web эксперт
Перейти к: навигация, поиск

Form Submission 101: GET Versus POST

FORM"s METHOD can be set to either GET or POST.

GET, which is the default setting, passes the form values on the URL.

The following simple form can be used as an example.



   <source lang="javascript">

<FORM ACTION=http://www.wbex.ru METHOD=GET>

     <SELECT NAME=STATE>
       <OPTION VALUE=NC>North Carolina</OPTION>
       <OPTION VALUE=SC>South Carolina</OPTION>
       <OPTION VALUE=CA>California</OPTION>
     </SELECT>
     <INPUT TYPE="button" VALUE="Submit">

</FORM></source>


When POST is used, the browser contacts the URL specified in the ACTION property and sends the data in the body of the HTTP request.

If you are sending large amounts of form information to the server, the POST method should be used.

The POST method is also useful for keeping your data from being easily seen.

Get form method value

   <source lang="javascript">

<html> <head> <title>Online Survey</title> </head> <body> <form action="http://www.wbex.ru" method="POST" name="MyForm">

wbex.ru - Online Survey

Your Name:   <input type="text" name="YourName"/>
Your Gender:  
  <input type="radio" name="Gender" value="Male"/>Male
<input type="radio" name="Gender" value="Female"/>Female
Which of our consultancy
services are you interested in?
 
  <input type="checkbox" name="Java"/> Java
<input type="checkbox" name="Javascript"/> Javascript
<input type="checkbox" name="SVG"/> SVG
<input type="checkbox" name="XSL-FO"/> XSL-FO
<input type="checkbox" name="ASP.Net"/> ASP.Net
Which free gift would you prefer for filling out this survey?  
 <select name="FreeGift">
  <option value="Choice1">AAA</option>
  <option value="Choice2">BBB</option>
  <option value="Choice3">CCC</option>
 </select>
Enter your comments in
the text box
  <textarea name="Comments" rows="5" cols="50"> </textarea>
   
<input type="submit" value="Send Form"/>

</form> <script type="text/javascript" language="javascript">

</script> </body> </html></source>