在提交之前从表单生成报告以进行确认

时间:2015-04-26 09:52:30

标签: javascript forms report confirm

我有复选框的表单(实际上是单选按钮而不是复选框)。我想创建一个包含已检查选项列表的报告。该报告应在提交表格中确认。这该怎么做?我的代码中已经有两个其他功能。我的表单看起来类似于下面的表格

<form method="POST" action="add.php" onSubmit="return otherFunction();">
 <?php
while($linia=mysql_fetch_array($result)){
  echo "<tr><td>".$linia['Description']."</td><td><input type='radio' name='check".$i."' value='1' onClick='activeFunction(".$i.")'><input type='hidden' name='vcheck".$i."' value='".$linia['Id_description']."'></td>";	
}
<button type='submit'>Send form</button>
?>

我需要它像这样工作:有人检查一些这个单选按钮然后单击提交然后这个人应该看到选中的选项来阅读它并确认是否没有错误。他/她没有检查他想要的选项之一

1 个答案:

答案 0 :(得分:0)

我会将函数调用放在按钮上,如下所示:

package test;

import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

public class MainClass {

    private static final Random RANDOM = new Random();

    private static final ConcurrentHashMap<Integer, Boolean> MAP = new ConcurrentHashMap<Integer, Boolean>();

    private static final Integer KEY = 1;

    private static final Thread DELETING_THREAD = new Thread() {

        @Override
        public void run() {
            while (true) {
                MAP.entrySet().removeIf(entry -> entry.getValue() == false);
            }
        }

    };

    private static final Thread ADDING_THREAD = new Thread() {

        @Override
        public void run() {
            while (true) {
                boolean val = RANDOM.nextBoolean();

                MAP.put(KEY, val);
                if (val == true && !MAP.containsKey(KEY)) {
                    throw new RuntimeException("TRUE value was removed");
                }

            }
        }

    };

    public static void main(String[] args) throws InterruptedException {
        DELETING_THREAD.setDaemon(true);
        ADDING_THREAD.start();
        DELETING_THREAD.start();
        ADDING_THREAD.join();
    }
}

您的表单标签应如下所示:

<button onClick="otherFunction()">Send Form</button>
<script>
function otherFunction() {
    if (confirm('Sure you want to submit the form?')) {
         // you'd have to give you form an id like 'myform' first
         document.getElementById('myform').submit();
    }
    else {
         // not sending the form, maybe do something else here
    }

}
</script>