[英]Automatic form submission using JS
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> </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> </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 提前致谢
Try this pure javascript, 试试这个纯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> </TD></TR>
<TR>
<TD align="right" width="40%">Regd. No:</TD>
<TD><INPUT type="text" name="stid" value=""></TD>
</TR>
<TR><TD> </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">
. 要访问此document.getElementById('myform').submit()
,应将<INPUT type="submit" name="submit" value="Submit">
更改为<INPUT type="submit" name="submit_button" value="Submit">
。 Don't use other element with name of submit
or id. 请勿使用其他名称为submit
或ID的元素。
And also the better one is, 而且更好的是
<script>
window.ready = function(){
document.getElementById('myform').submit();
};
</script>
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. 我仍然不明白页面加载后提交表单的意义。
try 尝试
<script>
function submitme()
{
document.forms["performance"].submit();
}
</script>
or 要么
<script>
function submitme()
{
document.forms[0].submit();
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.