Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Created October 30, 2015 13:26
Show Gist options
  • Save JustusAdam/790fefd1537bf015db7f to your computer and use it in GitHub Desktop.
Save JustusAdam/790fefd1537bf015db7f to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="main.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function reset_geschlecht () {
var frau_input = document.getElementById("frau-input");
var mann_input = document.getElementById("mann-input");
frau_input.labels[0].style.color = "black";
mann_input.labels[0].style.color = "black";
}
function reset_style() {
reset_geschlecht();
}
function validate(form) {
var ist_valide = true;
var message = "";
var frau_input = document.getElementById("frau-input");
var mann_input = document.getElementById("mann-input");
if (mann_input.checked === false && frau_input.checked === false) {
ist_valide = false;
console.log("Geschlecht input fehlt");
frau_input.labels[0].style.color = "red";
mann_input.labels[0].style.color = "red";
message += "Bitte geben sie ein Geschlecht an\n";
} else {
reset_geschlecht();
}
var name_input = document.getElementById("name-input");
if (name_input.value === "") {
ist_valide = false;
name_input.labels[0].style.color = "red";
message += "Bitte geben sie ihren Namen an\n";
}
var feedback_input = document.getElementById("feedback-input");
if (feedback_input.value === "") {
ist_valide = false;
feedback_input.labels[0].style.color = "red";
message += "Bitte geben sie ihr feedback ein\n";
}
var email_input = document.getElementById("email-input");
if (email_input.value === "") {
ist_valide = false;
email_input.labels[0].style.color = "red";
message += "Bitte geben sie ihre email addesse an\n";
}
if (!ist_valide) alert(message);
return ist_valide;
}
function validate_mail(email) {
return /\w[a-z0-9_.-]*@[a-z0-9_.-]*\.\w+/.test(email);
}
</script>
</head>
<body>
<div>
<h2>Feedback</h2>
<!-- <form action="mailto:[email protected]"> -->
<form action="#" onsubmit="return validate(this);">
<p>
<label for="mann-input">Mann:</label>
<input id="mann-input" type="radio" value="Mann" name="Geschlecht" />
<label for="frau-input">Frau:</label>
<input id="frau-input" type="radio" value="Frau" name="Geschlecht" />
</p>
<p>
<label for="name-input">Name * :</label>
<input id="name-input" name="Name" type="text" />
</p>
<p>
<label for="vorname-input">Vorname:</label>
<input id="vorname-input" name="Vorname" type="text" />
</p>
<p>
<label for="email-input">Email :</label>
<input id="email-input" name="Email" type="text" />
</p>
<p>
<label for="feedback-input">Feedback :</label>
<textarea id="feedback-input"></textarea>
</p>
<p>
<input type="button" value="Reset" onclick="reset_style()" />
<input type="submit" />
</p>
</form>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment