割り当てを実行しようとしていますが、コードを検証するのに問題があります。問題は、「@」が存在するかどうかを確認するためにフォームにメールテキストボックスが必要ですが、同じフォームでも名前テキストボックスが空かどうかを確認する必要があることです。一度に動作させることができるのはそのうちの 1 つだけです。
これは私のコーディングです。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Weclome to the Recipe Collection Website</title>
<script>
function validateForm()
{
var x=document.forms["myForm"]["name"].value;
if (x==null || x=="")
{
alert("Name text box must be filled out");
return false;
}
</script>
<script>
function checkEmail()
{
var y=document.forms["myForm"]["email"].value;
var atpos=y.indexOf("@");
var dotpos=y.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=y.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Number of recipes previously submitted: <input type="radio" name="recipes" value="0">0<br>
<input type="radio" name="recipes" value="1-2">1-2<br>
<input type="radio" name="recipes" value="3-4">3-4<br>
<input type="radio" name="recipes" value="5+">5+<br>
Have you ever submitted recipes to another site?: <input type="radio" name="othersite" value="yes">Yes<br>
<input type="radio" name="othersite" value="no" checked>No<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
この道はずれですか?
助けてくれてありがとう。