Get input value from form control : Form « Form Control « JavaScript DHTML






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

1.Form length
2.On focus event
3.On focus lost event
4.Add event listener to form
5.Add event listener to elements in a form