Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Cách sử dụng thuộc tính formaction trong HTML

Thuộc tính formaction trên nút submit (<button type="submit"> hoặc <input type="submit">) ghi đè action của form, cho phép nhiều nút gửi đến URL khác nhau.

Lưu ý: Không hỗ trợ trên IE9 và cũ hơn.

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <title>HTML formaction attribute</title>
  </head>
  <body>
    <form action="/new1.php" method="get">
      Tên học sinh: <input type="text" name="name"><br>
      Môn học: <input type="text" name="subject"><br>
      <button type="submit">Gửi mặc định</button><br>
      <button type="submit" formaction="/new2.php">Gửi trang khác</button>
    </form>
  </body>
</html>