Get input value from form control
<html>
<head>
<title>Just Your Basic Form</title>
<script type = "text/javascript">
function alertName() {
var name = document.forms[0].nametext.value;
if (name == "a") {
document.write("a value");
}
else if (name == "b") {
document.write("b value.");
}
else {
document.write("else: " + name);
}
return true;
}
</script>
</head>
<body>
<form id="myform" action="#" onsubmit="return alertName();">
<p>Username: <input id="nametext" name="username" type="text" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
Related examples in the same category