确认框出现两次

时间:2011-11-24 08:05:51

标签: javascript forms confirmation

我在javascript中有一个确认框。确认框有效但有轻微的故障。当确认框显示时,如果我单击确定或取消,该框将关闭并再次打开,要求第二次确认,如果我第二次单击确定或取消该框,则它将提交表单。为什么会两次显示确认信息?

下面是代码:(myClickHandler()是一个按钮的函数,validation()是一个函数,我的表单的验证就出现了)

 function validation() {

                var isDataValid = true;

                var sessionNoO = document.getElementById("sessionNo");               
                var questionNumberO = document.getElementById("txtQuestion");
                var roomTextO = document.getElementById("room");

                var errSessionMsgO = document.getElementById("sessionNoAlert");
                var errQuesMsgO = document.getElementById("numberAlert");
                var errRoomMsgO = document.getElementById("roomAlert");

                var trimmedRoomText = roomTextO.value.replace(/^\s+/, '').replace(/\s+$/, '');



   if (sessionNoO.value == ""){
          errSessionMsgO.innerHTML = "Please Enter in the Number of Sessions you Require";
          isDataValid = false;   
    }else if (sessionNoO.value == 0){
        errSessionMsgO.innerHTML = "Number of Sessions Must be More than 0";
          isDataValid = false;
      }else{
                errSessionMsgO.innerHTML = ""; 
            }


    if(questionNumberO.value == 0){
        errQuesMsgO.innerHTML = "Please Set the Number of Questions";
        isDataValid = false;
    } else {
        errQuesMsgO.innerHTML = "";
    } 

          if (roomTextO.value == ""){
          errRoomMsgO.innerHTML = "Please Enter in a Room Number";
          isDataValid = false;
            }else if (!trimmedRoomText.length){
          errRoomMsgO.innerHTML = "Please Enter in a Room Number"; 
          isDataValid = false;      
        }else{
                errRoomMsgO.innerHTML = ""; 
            }

            return isDataValid;

            }

            function submitform()
            {

        var sessionFormO = document.getElementById("sessionForm");

        sessionFormO.submit();

            }    


    function myClickHandler()
    {
        if(validation())
        {
            showConfirm(); 
        }
    }


    function showConfirm()
    {
        var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards your Session.Are you sure you want to Proceed? ");

        if (confirmMsg==true)
        {
            submitform();   
        } else {
            parent.close();    
        }
    }

Html代码(提交表单并显示确认框的按钮如下):

<form action="QandATable.php" method="post" id="sessionForm">
    <p><strong>10: </strong><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="myClickHandler()"/></p> 
</form>

0 个答案:

没有答案