在尝试获得结果时,onSubmit不起作用

时间:2018-04-23 09:55:23

标签: javascript html

您好我正在提交调查问卷并尝试使用onSubmit获取结果,但它无效

的JavaScript

function results_addition(){
  var results = total + Details + formElement;

  if(results<30){
    document.submit_form.choice1.value="Low Risk";
  }else{
    if(results>50){
      document.submit_form.choice1.value="High Risk";
    }else{
      document.submit_form.choice1.value="Medium Risk";
    }
  }
}

HTML

<form name="choice1" onSubmit="results_addition()">
<input type="submit" value="Submit">

3 个答案:

答案 0 :(得分:0)

请尝试onsubmit代替onSubmit,然后添加结束</form>代码

答案 1 :(得分:0)

<html>
<body>

<p>When you submit the form, a function is triggered which alerts some text.</p>

<form name="choice1" onSubmit="results_addition()">
<input type="submit" value="Submit">
</form>

<script>
function results_addition(){
alert("hello")
}
</script>

</body>
</html>

我尝试了相同的表单并且正在运行我认为您还没有正确关闭表单。

答案 2 :(得分:0)

  1. 更改

    <form name="choice1" onSubmit="results_addition()">

    <form name="choice1" onSubmit="return results_addition()">

  2. 在函数末尾添加以下内容

    return false;