因此,我试图在 html 中创建一个 javascript 函数,该函数将接受电子邮件地址,然后将它们提交到 Web 表单。我该怎么做呢?这就是我到目前为止所拥有的:
<html>
<form name="form" method="post" action="form-action.php">
<label>
Email:
</label>
<input type="email" name="email"
id="email" size="25" />
<input type="button" value="Submit" onclick="SubmitEmail()" />
</form>
<script type="text/javascript">
function SubmitEmail() {
if (!ValidateForm()) {
return false;
}
document.getElementById("form").submit();
function ValidateForm() {
if (document.getElementById('email').value.length === 0) {
alert("Email is Required");
return false;
}
document.getElementById('EmailRslt').value = document.getElementById('email').value;
return true;
}
</script>
<td>Your Email is:
</td>
<td id="EmailRslt"></td>
</html>