在特殊情况下绕过验证 [英] bypass validation in special cases

查看:69
本文介绍了在特殊情况下绕过验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在建立一个在线考试网络应用程序。它有一个radiobuttonlist(用于选项)和一个按钮(btnNext)。现在,考生必须检查radiobuttonlist以转到下一个问题,否则javascript验证将显示一条消息并阻止提交。但是,即使在计时器用完时没有选择任何选项,客户也希望提交应用程序。

我基本上做的是,我刚刚调用了btnNext当计时器用完时,.click()函数...现在问题是按钮点击将再次触发验证...并且消息不断弹出。那么,有没有办法可以绕过这种特殊情况的验证?...即如果计时器用完就可以提交空的答案......

这是我的按钮,

 <   asp:按钮    ID   =  btnNext    runat   =   server   高度 < span class =code-keyword> =  26px    OnClick   =  btnNext_Click    

文本 = 下一步 宽度 = 77px / >





javascript验证...



<前lang =Javascript> 功能 CheckIfOptionSelected(){

var radioButton1 = document .forms [ 0 ]。elements [' ctl00_MainContent_rdBtnListOptions_0'];
var radioButton2 = document .forms [ 0 ]。elements [' ctl00_MainContent_rdBtnListOptions_1'];
var radioButton3 = document .forms [ 0 ]。elements [' ctl00_MainContent_rdBtnListOptions_2'];
var radioButton4 = document .forms [ 0 ]。elements [' ctl00_MainContent_rdBtnListOptions_3'];

if (radioButton1.checked!= true && radioButton2。已检查!= true && radioButton3.checked!= true && radioButton4.checked! = true ){
alert(' 请在继续)之前选择一个答案;
return false ;
}
else {
countdownReset();
}
返回 true ;

}





我已经在page_load处理程序上添加了onclick属性,



 受保护  void  Page_Load ( object  sender,EventArgs e)
{
btnNext.Attributes.Add( onclick return CheckIfOptionSelected());
}





定时器jquery

<前lang =Javascript> $( document )。ready( function (){
........... ........
如果(countdownCurrent == 0 ){

var btn = document .getElementById(' <%= btnNext.ClientID%>');
btn.click();
// countdownReset();
}



任何建议或更正都会有所帮助,

提前致谢

解决方案

document ).ready( function (){
...................
if (countdownCurr ent == 0 ){

var btn = document .getElementById(' <%= btnNext.ClientID%>'< /跨度>);
btn.click();
// countdownReset();
}



任何建议或更正都会有所帮助,

提前致谢


我想到了。我将onClientClick添加到按钮以激活验证器,并返回true或false,如果为true,则触发服务器端单击事件。

 onclientclick =return validator(); 



对于未经验证的提交,我只会从按钮元素中删除onclick属性。



我想你可以使用Javascript删除按钮属性onclick。我不确定我的下面是否正确。猜猜你可以通过getElementById代替元素类型来实现它

 document.getElementsByTagName(input.type ==''submit'')[0] .removeAttribute(onClick ); 



我知道你可以使用JQuery prop

 


button.prop (onclick,null);


Hello everyone, i am building an online examination web application. It has a radiobuttonlist(for options) and a button(btnNext). Now, an examinee must check the radiobuttonlist to go to the next question or else a javascript validation will show a message and prevent submit. However, the client want''s the application to submit, even if no options are selected when the timer runs out.
What i''ve basically done is, i''ve just called the btnNext.click() function when the timer runs out...now the problem is the button click will again trigger the validation...and the message keeps popping up. So, is there a way i can bypass the validation for this special case?...i.e if the timer runs out then it is ok to submit empty anwer...
This is my button,

<asp:Button ID="btnNext" runat="server" Height="26px" OnClick="btnNext_Click" 

                     Text="Next" Width="77px" />



javascript validation...

function CheckIfOptionSelected() {

            var radioButton1 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_0'];
            var radioButton2 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_1'];
            var radioButton3 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_2'];
            var radioButton4 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_3'];

            if (radioButton1.checked != true && radioButton2.checked != true && radioButton3.checked != true && radioButton4.checked != true) {
                alert('Please select an answer before you proceed');
                return false;
            }
            else {
                countdownReset();
            }
            return true;
            
        }



i''ve added the onclick attribute on page_load handler as,

protected void Page_Load(object sender, EventArgs e)
{
 btnNext.Attributes.Add("onclick", "return CheckIfOptionSelected()");
}



Timer jquery

$(document).ready(function () {
...................
if (countdownCurrent == 0) {
                    
    var btn = document.getElementById('<%=btnNext.ClientID%>');
    btn.click();
    //countdownReset();
}


Any advice or correction would be helpful,
Thanks in advance

解决方案

(document).ready(function () { ................... if (countdownCurrent == 0) { var btn = document.getElementById('<%=btnNext.ClientID%>'); btn.click(); //countdownReset(); }


Any advice or correction would be helpful,
Thanks in advance


I thought about it. I would add onClientClick to the button to fire the validator, and return true or false, if true, fire the server side click event.

onclientclick="return validator();"


For the submit without validation, I would just delete the onclick attribute from the button element.

I think you can delete the button attribute "onclick" using Javascript. I''m not sure if I got the line below right. Guess you can do it by getElementById instead of element type

document.getElementsByTagName("input.type==''submit''")[0].removeAttribute("onClick"); 


I know you can using JQuery prop


button.prop("onclick", null);


这篇关于在特殊情况下绕过验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆