简体   繁体   English

如何在有序列表中显示功能的输入

[英]How to display inputs of a function in an ordered list

I need to make a code that creates a form, having three interests. 我需要编写一个代码,创建一个具有三个兴趣的表单。 When the usere submits them, they need to appear in a list. 当用户提交它们时,它们需要出现在列表中。 So far, i have this coding: 到目前为止,我有此编码:

When I click on "submit" i do not get directed anywhere though. 当我单击“提交”时,我不会被指引到任何地方。

<html>
   <head>
    <script>
function validateForm()
{var x=document.forms["myForm"]["interest1"].value;
var y=document.forms["myForm"]["interest2"].value;
var z=document.forms["myForm"]["interest3"].value;

}
</head>
    </script>

    <body>
      <form name="myForm" action="demo_form.asp" onsubmit=return validateForm()" method="post">
        Interest 1:<input type="text"  name="interest1">
        Interest 2:<input type="text" name="interest2">
        Interest 3:<input type="text" name="interest3">
        <input type="submit" value="Submit">
      </form>


    </body>
</html>

i need to use a for loop for getting the submitted values. 我需要使用一个for循环来获取提交的值。 How do I do this? 我该怎么做呢?

Since you're returning the function on submit, try returning true from your function if you want to submit 由于您是在提交时返回函数,因此如果要提交,请尝试从函数返回true

<script>
function validateForm() {
    var x=document.forms["myForm"]["interest1"].value;
    var y=document.forms["myForm"]["interest2"].value;
    var z=document.forms["myForm"]["interest3"].value;

    // TODO: validate x, y and z

    return true;
}
</script>

Your closing tags are ordered incorrectly also, make sure </script> occurs before </head> . 您的结束标记的顺序也不正确,请确保</script>出现在</head>之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM