What is the use of target attribute in HTML form tag?

user2823982 picture user2823982 · Mar 26, 2014 · Viewed 33.2k times · Source

While I was implementing a file upload progress bar in PHP, I saw this target attribute in form tag. The code was like this:

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" 
      method="POST" id="myForm" 
      enctype="multipart/form-data" 
      target="hidden_iframe">

What is the use of this target attribute here?

Actually, after submitting this form data (file) we track the upload progress from another page say upload.php. Could we implement this without the target attribute?

Answer

David Lin picture David Lin · Mar 26, 2014

That is used to specify in which window you would like to show the response from the remote server upon submitting your form.

Possible values are :

  • _blank - new page
  • frame - show in the iframe with the given name
  • _self - show in the same iframe where the form locates
  • _parent - show in the parent page/iframe of the form's iframe
  • _top - the top most window