JavaScript Tutorial/Form/Method

Материал из Web эксперт
Версия от 18:52, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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.



<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>


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

<html>
<head>
<title>Online Survey</title>
</head>
<body>
<form action="http://www.wbex.ru" method="POST" name="MyForm">
<table width="600">
<tr><th colspan="3" align="center">wbex.ru - Online Survey<br /><br /></th>
</tr>
<tr>
 <td>Your Name:</td>
 <td>&nbsp;</td>
 <td><input type="text" name="YourName"/></td></tr>
<tr>
 <td>Your Gender:</td>
 <td>&nbsp;</td>
 <td>
   <input type="radio" name="Gender" value="Male"/>Male<br />
   <input type="radio" name="Gender" value="Female"/>Female<br />
 </td>
</tr>
<tr><td>Which of our consultancy <br />services are you interested in?</td>
 <td align="right">&nbsp;
 </td>
 <td>
   <input type="checkbox" name="Java"/>&nbsp;Java<br />
   <input type="checkbox" name="Javascript"/>&nbsp;Javascript<br />
   <input type="checkbox" name="SVG"/>&nbsp;SVG<br />
   <input type="checkbox" name="XSL-FO"/>&nbsp;XSL-FO<br />
   <input type="checkbox" name="ASP.Net"/>&nbsp;ASP.Net<br />
 </td>
</tr>
<tr>
 <td>Which free gift would you prefer for filling out this survey?</td>
 <td>&nbsp;</td>
 <td>
  <select name="FreeGift">
   <option value="Choice1">AAA</option>
   <option value="Choice2">BBB</option>
   <option value="Choice3">CCC</option>
  </select>
</tr>
<tr>
 <td>Enter your comments in<br />the text box
 </td>
 <td>&nbsp;</td>
 <td><textarea name="Comments" rows="5" cols="50"> </textarea></td>
</tr>
<tr>
 <td>&nbsp;</td>
 <td>&nbsp;</td>
 <td><br /><input type="submit" value="Send Form"/></td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
<!-- //
document.write("<P>The method property has the value: <b>" + document.MyForm.method + "</b></p>");
// -->
</script>
</body>
</html>