ปุ่มฟอร์มใน JavaScript

คุณรู้อยู่แล้วว่าฟอร์มจะถูกส่งเมื่อ กดปุ่ม อย่างไรก็ตาม มีรายละเอียดปลีกย่อยอยู่ ปุ่มจะต้องมีแอตทริบิวต์ type ที่มีค่าเป็น submit:

public/form.html<form>
  <input name="test1">
  <input name="test2">
  <input type="submit">
</form>

ฟอร์มจะถูกส่งโดยแท็ก button ที่มีแอตทริบิวต์ type ค่า submit ด้วย:

public/form.html<form>
  <input name="test1">
  <input name="test2">
  <button type="submit">btn</button>
</form>

ฟอร์มจะถูกส่งเช่นกัน หากอยู่ในอินพุตใด ๆ โฟกัสและกด Enter

ปุ่มที่มีแอตทริบิวต์ type ค่า button ใช้เป็นองค์ประกอบของหน้าเว็บ และจะไม่ส่งฟอร์ม:

public/form.html<form>
  <input name="test1">
  <input name="test2">
  <input type="button">
</form>

แท็ก button จะทำงานในลักษณะเดียวกัน:

public/form.html<form>
  <input name="test1">
  <input name="test2">
  <button>btn</button>
</form>

ปุ่มที่มีแอตทริบิวต์ type ค่า reset จะล้างฟอร์มที่กรอกข้อมูล:

public/form.html<form>
  <input name="test1">
  <input name="test2">
  <input type="reset">
  <input type="submit">
</form>
Задание 1

แก้ไขโค้ดต่อไปนี้ เพื่อให้ปุ่มส่งฟอร์ม ไปยังเซิร์ฟเวอร์:

html<form>
  <input name="name">
  <input name="surn">
  <button>send</button>
</form>