gpt4 book ai didi

javascript - 使用JS自动提交表单

转载 作者:行者123 更新时间:2023-11-28 13:39:15 24 4
gpt4 key购买 nike

我正在开发一个代码,它以一个值作为输入,提交时以表单显示结果,代码如下:

<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>

问题是,当页面加载完成时,应该提交表单,但是却无法提交表单。有什么问题,帮帮我!!提前致谢

最佳答案

尝试这个纯 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>

访问此document.getElementById('myform').submit() ,你应该改变 <INPUT type="submit" name="submit" value="Submit"><INPUT type="submit" name="submit_button" value="Submit"> 。不要使用名称为 submit 的其他元素或 ID。

而且更好的是,

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

关于javascript - 使用JS自动提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19079964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com