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. How do I do this?
Since you're returning the function on submit, try returning true from your function if you want to submit
<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>
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.