Javascript Form How to - Check form target attribute








Question

We would like to know how to check form target attribute.

Answer


<html>
    <body>
    <script language="JavaScript">
    function show(){<!-- w ww  .j  av  a2  s .  c om-->
        var tar = document.form1.target;
        if(tar == "_self"){
          console.log("this window");
        } else{
          console.log("The target has not been specifically specified");
        }
    }
    </script>
    <form name="form1" action="post" target="_self">
    <br><br><br>
    <input type="button" value="submit" onClick='show()'>
    </form>
    </body>
</html>

The code above is rendered as follows: