首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用表单填充数组

使用表单填充数组
EN

Stack Overflow用户
提问于 2018-07-08 05:41:10
回答 0查看 70关注 0票数 0

我正在尝试制作一个表单,它应该按照所提出的问题确定的顺序创建一个数组。我正在努力尝试js,但我发现它很难,没有经验。它不工作并不让我感到惊讶。不知怎么的,这些变量没有值。我已经做的事情很可能是愚蠢的,我认为它们可以缩短一点;-)。希望有人会看看我的代码,并帮助我解决这个问题。

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
 <head>
  <title>Keuze studievereniging</title>
  <style>
    fieldset {max-width:500px;}
    button {margin-top:30px;}
  </style>
</head>
  <body>
<h2>Sororities hulp</h2>

<p>Beantwoord onderstaande vragen om te zien welke vereniging het best bij je past.</p>

<form name="formulier"
onsubmit="return validateForm()" method="post">
  <fieldset>
  <legend>Maak je keuze per vraag, vul alle onderdelen in.</legend>
  <div>
<p>Do you believe it is important that faith is emphasized in a sorority?</p>
  <input type="radio" id="vr1_1" name="VR1" value=1> Ja
  <input type="radio" id="vr1_0" name="VR1" value=0> Nee
<p>Would you participate in a hazing?</p>
  <input type="radio" id="vr2_1" name="VR2" value=1> Ja
  <input type="radio" id="vr2_0" name="VR2" value=0> Nee
<p>Would you like to fully integrate within the community of the sorority?</p>
  <input type="radio" id="vr3_1" name="VR3" value=1> Ja
  <input type="radio" id="vr3_0" name="VR3" value=0> Nee
<p>Do you like to party?</p>
  <input type="radio" id="vr4_1" name="VR4" value=1> Ja
  <input type="radio" id="vr4_0" name="VR4" value=0> Nee
<p>Would you sacrifice a free night of your own for the good of the sorority?</p>
  <input type="radio" id="vr5_1" name="VR5" value=1> Ja
  <input type="radio" id="vr5_0" name="VR5" value=0> Nee
<p>Would you like your sorority to be apart of a bigger european system?</p>
  <input type="radio" id="vr6_1" name="VR6" value=1> Ja
  <input type="radio" id="vr6_0" name="VR6" value=0> Nee
<p>Would you enjoy a weekly or by weekly bible study?</p>
  <input type="radio" id="vr7_1" name="VR7" value=1> Ja
  <input type="radio" id="vr7_0" name="VR7" value=0> Nee <br>
<button type="submit">Adviseer mij</button>
  </div>
</fieldset>
</form>

<p>De voor jou geschikste volgorde om te kijken is: </p>

<p id="uitslag"></p>

  <script type="text/javascript">

  function validateForm() {
  var x = document.forms["formulier"]["VR1", "VR2", "VR3", "VR4", "VR5", "VR6", "VR7"].value;
  if (x == "") {
      alert("You have to answer each question for a good advice");
      return false;
  }
}

    var vvr11 = document.getElementsByName(vr1_1);
    console.log (vvr11);
    var vvr10 = document.getElementsByName(vr1_0);
    var vvr21 = document.getElementsByName(vr2_1);
    var vvr20 = document.getElementsByName(vr2_0);
    var vvr31 = document.getElementsByName(vr3_1);
    var vvr30 = document.getElementsByName(vr3_0);
    var vvr41 = document.getElementsByName(vr4_1);
    var vvr40 = document.getElementsByName(vr4_0);
    var vvr51 = document.getElementsByName(vr5_1);
    var vvr50 = document.getElementsByName(vr5_0);
    var vvr61 = document.getElementsByName(vr6_1);
    var vvr60 = document.getElementsByName(vr6_0);
    var vvr71 = document.getElementsByName(vr7_1);
    var vvr70 = document.getElementsByName(vr7_0);

    var alpha = vvr11 + vvr31 + vvr41;
    console.log (alpha);
    var rsk = vvr11 + vvr51 + vvr71;
    var vgste = vvr11 + vvr51 + vvr71;
    var nse = vvr11 + vvr51 + vvr71;
    var audentis = vvr21 + vvr41 + vvr51;
    var taste = vvr21 + vvr31 + vvr41;
    var aegee = vvr31 + vvr41 + vvr61;

    var sororities = [alpha, rsk, vgste, nse, audentis, taste, aegee];

    function sortering() {
        sororities.sort(function(a, b){return a - b});
        document.getElementById("uitslag").innerHTML = sororities;
    }
    sortering ();
   </script>

  </body>
 </html>
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51227139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档