简体   繁体   English

如果满足条件,则自动单击“提交”按钮

[英]click submit button automatically if a condition is satisfied

I am making an online examination system in PHP.this is a part of my huge examination code..every thing is working well.When the time is up, the page is redirecting to result page by 我正在用PHP开发一个在线考试系统。这是我庞大的考试代码的一部分..一切正常。时间到了,页面将重定向到结果页面

window.location = "http://localhost/result.php";//which is in comment line

but here the value of answers are not posting. 但此处的答案值未发布。 But when i click the submit button it works. 但是,当我单击提交按钮时,它可以工作。 So i make a function to submit the form automatically.but it is not working , dont know why. 所以我做了一个功能来自动提交表单。但它不起作用,不知道为什么。 Here "if" block is checking whether the time is up or not. 此处的“ if”块正在检查时间是否到了。 if up then do the following. 如果向上,请执行以下操作。 Inside "if" I want either to click the "submit button" 在“如果”内,我想单击“提交按钮”

 echo '<input type="submit" name="submit" id="submit" value="SUBMIT"/></FORM>'; 

or submit the the form, so that i can get the result in next page- "result.php". 或提交表格,以便我可以在下一页“ result.php”中获得结果。

<FORM name ='form1' id='form1' method ='post' action='result.php' >

Thanks in advance. 提前致谢。 Hope you understand my problem. 希望你理解我的问题。

function myfunc () {
    var frm = document.getElementById("form1");
    frm.submit();
}

document.getElementById("remain").innerHTML = hours+" hours : "+minutes+" minutes : "+seconds+" seconds";
SD=window.setTimeout( "setCountDown()", 1000 );
if (minutes == '00' && seconds == '00') { seconds = "00"; window.clearTimeout(SD);
    window.alert("Time is up. Press OK to continue.");
    window.onload = myfunc;
    //document.form1.submit();
    //window.location = "http://localhost/result.php"
}

Try this.. 尝试这个..

window.onload = function(){
    myfunc();
};

If you're trying to submit the form after window.alert("Time is up. Press OK to continue.") shows, you don't need a load event. 如果您尝试在window.alert("Time is up. Press OK to continue.")显示之后提交表单,则不需要加载事件。 You can just put your code immediately after the alert and it will run once the alert is closed (by clicking 'okay'): 您只需将代码放在警报后,它就会在警报关闭后立即运行(通过单击“确定”):

alert("Time is up. Press OK to continue.");
myfunc();

Alternatively, you could use confirm instead of alert : 或者,您可以使用confirm而不是alert

var timesUp = confirm("Time is up. Press OK to continue.");

if (timesUp) {
    myfunc();
}

With a confirm you'll get two buttons and could run a different event for ok (true) and cancel (false). 进行confirm您将获得两个按钮,并可以针对ok (true)和cancel (false)运行不同的事件。 One of these options should solve your problem though. 这些选项之一应该可以解决您的问题。

只需使用此document.form1.submit.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM