0

I am developing a code, which takes a value as input and the form when submitted, displays the result and the code is as follows:

<script>
function submitme()
{

    document.forms["myform"].submit();
}
</script>
<body onload="submitme()">
<FORM name="performance" id="myform" method="post" action="http://www.pvpsiddhartha.ac.in/index.sit" >
        <INPUT type="hidden" name="service" value="STU_PERFORMANCE_MARKS_DISPLAY">
          <TABLE border="0" width="100%" cellspacing="0" cellpadding="0">
            <TR>
              <TD colspan="2" align="center"><STRONG><U>Student Marks Performance Display Form</U></STRONG></TD>
            </TR>  
            <TR><TD>&nbsp;</TD></TR>
            <TR>
              <TD align="right" width="40%">Regd. No:</TD>
              <TD><INPUT type="text" name="stid" value="<?php echo $_GET['x']; ?>"></TD>
            </TR>
            <TR><TD>&nbsp;</TD></TR>
            <TR>
              <TD align="right"><INPUT type="submit" name="submit" value="Submit"></TD>
              <TD align="center"><INPUT type="reset" value="Clear"></TD>
            </TR>
          </TABLE>
        </FORM>
        </body>

The problem is, when the page is loaded completely, the form should be submitted , but the form cannot be submitted. What is the problem , Help me!! Thanks in advance

6
  • 1
    Your script tag is not inside <body> nor <head>. Commented Sep 29, 2013 at 15:49
  • when I add an alert("hello"); , it is being invoked but the submition is not done @Bart Commented Sep 29, 2013 at 15:52
  • either use document.getElementById('myForm') or document.forms[0] Commented Sep 29, 2013 at 15:53
  • The same problem , i cant submit @OhadMilchgrub Commented Sep 29, 2013 at 15:54
  • there's a problem with the name of the button input that overrides the submit function of the form. change the name of the button from submit to something else (or remove it altogether) Commented Sep 29, 2013 at 16:00

3 Answers 3

3

Try this pure javascript,

  <body>
    <FORM name="performance" id="myform" method="post" action="http://www.pvpsiddhartha.ac.in/index.sit" >
      <INPUT type="hidden" name="service" value="STU_PERFORMANCE_MARKS_DISPLAY">
        <TABLE border="0" width="100%" cellspacing="0" cellpadding="0">
          <TR>
            <TD colspan="2" align="center"><STRONG><U>Student Marks Performance Display Form</U></STRONG></TD>
          </TR>  
          <TR><TD>&nbsp;</TD></TR>
          <TR>
            <TD align="right" width="40%">Regd. No:</TD>
            <TD><INPUT type="text" name="stid" value=""></TD>
          </TR>
          <TR><TD>&nbsp;</TD></TR>
          <TR>
            <TD align="right"><INPUT type="submit" name="submit_button" value="Submit"></TD>
            <TD align="center"><INPUT type="reset" value="Clear"></TD>
          </TR>
        </TABLE>
      </FORM>

    <script>
        window.onload = function(){
          document.getElementById('myform').submit();
        };

    </script>

To access this document.getElementById('myform').submit(), you should change <INPUT type="submit" name="submit" value="Submit"> to <INPUT type="submit" name="submit_button" value="Submit">. Don't use other element with name of submit or id.

And also the better one is,

   <script>
    window.ready = function(){
      document.getElementById('myform').submit();
    };
  </script>
Sign up to request clarification or add additional context in comments.

Comments

1

It should help:

$(document).ready(function () {
    $('#myform').trigger('submit'); });

Still I don't get what is the point of submitting the form after page loads.

5 Comments

I automated the system, when I call a program, it automatically generates 10 numbers and opens 10 tabs filling each one in the textbox and submitting it!! just to reduce my work :)
I think he wants kind of redirect with post data.
yea yea @imsiso, please tell me how to do it
check my answer and also others all of them gives you different solutions.
@user2644795 - check this. stackoverflow.com/questions/4907843/…
1

try

<script>
function submitme()
{

    document.forms["performance"].submit();
}
</script>

or

<script>
function submitme()
{

    document.forms[0].submit();
}
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.