1
    <form name="formName" id="formName" action="" method="post" autocomplete="off"> 
        <input type="hidden" name="text1" id="text1" value='0' />
        <input  type="button" name ="submit" onClick="Submit()"  value="submit">
    </form>`
 <script>  
    function Submit() //my function
    {
        document.getElementById("formName").submit();
    }
</script>
I need some help... I have also tried `this document.formName.submit();` but still not working.

on debugging i got this error :Uncaught ReferenceError: formNameis not defined

2 Answers2

2

JavaScript code goes into a <script> tag, otherwise it is just rendered as text and is not interpreted as code.

<form name="formName" id="formName" action="" method="post" autocomplete="off"> 
    <input type="hidden" name="text1" id="text1" value='0' />
    <input  type="button" name ="submit" onClick="Submit()"  value="submit">
</form>`

<script>
    function Submit() //my function
    {
        document.getElementById("formName").submit();
    }
</script>

JavaScript is also case sensitive so "Submit" is not the same as "submit".

And you should never name a form input "submit", read: "Submit is not a function" error in JavaScript.

Sébastien
  • 11,860
  • 11
  • 58
  • 78
1

Your javascript code isn’t in tag. What you are going to do is taging and put your code between tags.

<script>
   Put Your codes here
</script>

And change submit() to Submit() in onClick