disable submit button after form submit and save the disable state of the button

烂漫一生 提交于 2020-01-26 03:47:05

问题


I have a page which has a form with questions and answers, upon submit I want to disable to button, and the user is taken to a thanks page. From that page when the user hits back button on browser he comes back to the form page(ques and ans page), at that point since he has already submitted the form i want the button to remain disabled to prevent from retaking the ques. I have the below code, but it is not serving the purpose sometimes its only working in FF and not in chrome. (upon going back). Any ideas here please? Thanks

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

来源:https://stackoverflow.com/questions/32316116/disable-submit-button-after-form-submit-and-save-the-disable-state-of-the-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!