表单提交后禁用提交按钮并保存按钮的禁用状态

时间:2015-08-31 16:50:05

标签: javascript html coldfusion

我有一个页面,其中包含一个带有问题和答案的表单,提交后我想禁用按钮,用户将被带到感谢页面。当用户点击浏览器上的按钮时,他回到表单页面(ques和ans页面),此时他已经提交了表单,我希望按钮保持禁用状态以防止重新删除问题。我有下面的代码,但它没有服务于目的,有时它只在FF工作,而不是铬。 (回去的时候)。请问有什么想法吗?感谢

<cfif (isdefined("form.isSubmitted") and form.isSubmitted neq "")>
            <div id="intro">                                         
                        <div class="headline">
                            <h1>Thank You for Taking the test!</h1>
                        </div>   
              <div id="welcome2" class="col-sm-6 hidden-xs"> Thank you for taking the test </div>   
                                <div class="start">
                                    <a href="/xyz.cfm" class="btn btn-lg btn-block btn-submit btn-sd-yellow-grad bold margin-bottom-20 rounded-4x">
                                Create Account                          
                                    </a>
                                </div>      

        <cfelse>
    ques ans form
    </cfif>

<script type="text/javascript">
        function form_submit() {
            var all_quest_done = true;
            var question_count = document.getElementById('ques_count').value;
            var ans_found;
            var radio_answer;
            var ans_count;
            for (ques_index = 1; ques_index <= ques_count; ques_index++) {
                radio_answers = document.getElementsByName('ques' + ques_index);
                //alert(ques_index);
                ans_found = false;
                for (ans_index = 0; ans_index < radio_ans.length; ans_index++) {
                    if (radio_answers[ans_index].checked) {
                        ans_found = true;
                        break;
                    }
                }
                if (!ans_found) {
                    all_quest_done= false;
                    break;
                }
            }
        var response = true;
        if (!all_quest_done) {
                var confirm_message = 'Not all the questions have been done!'
                    do you want to submit?';
                response = confirm(confirm_message);
             if (response){
                  document.getElementById("qSubmit").disabled = true;
                  return true;
             }else{
                return false;
             }
            }
        </script>
        <form action="abc.cfm" method="post" name="my_form" onSubmit="return form_submit();">
         <input type radio>
        Form with questions and answers goes here
        <input id="qSubmit" type="submit" value="I'M done" name="submit_now" class="btn" />
        </form>

0 个答案:

没有答案