Working with Basic Form Elements

Lecture Overview

HTML Forms

  <body>
    <form> </form>
  </body>

The <input> Element

Text Input Field

  <form>
    First name:
      <br>
        <input type="text" id="firstname">
      <br>
    Last name:
      <br>
        <input type="text" id="lastname">
  </form>

Text Input Submit Button

<form id="myform" action="JavaScript:myFunctionName()">
  First name:<br>
  <input type="text" id="firstname" ><br>
  Last name:<br>
  <input type="text" id="lastname" ><br><br>
  <input type="submit" value="Submit">
</form>

Responsive Forms

 <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" cont`ent="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Name Echoer</title>

        <script type="text/javascript">
            function evaluateUserInput(){
                let userInputFirstName = document.getElementById("first_name").value;
                let userInputLastName = document.getElementById("last_name").value;
                let outputDisplay = "Your name is: " + userInputFirstName + " " + userInputLastName;
                document.getElementById("output").innerHTML = outputDisplay;
                return false;
            }
        </script>
    </head>
    
    <body>
        <form id="myform">
          First name:<br><input id="first_name" type="text"><br>
          Last name:<br><input id="last_name" type="text"><br>
          <button id="submit_button" onClick="return evaluateUserInput();">Submit</button>
        </form> 
        <p id="output">placeholder text until the `submit_button` is clicked</p>
    </body>
</html>

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Simple Calculator</title>

        <script type="text/javascript">        
            function evaluateUserInput() {
                let refreshDomAfterTriggeringEvent = false;

                let firstValue = document.getElementById("first_value").value;
                let secondValue = document.getElementById("second_value").value;
                let operation = document.getElementById("operation").value;
                let expression = firstValue + operation + secondValue;
                let output = eval(expression);
                document.getElementById("output").innerHTML = output;

                return refreshDomAfterTriggeringEvent
            }
        </script>
    </head>
    
    <body>
        <form id="myform">
          First name:<br/><input id="first_name" type="text"/><br/>
          Last name:<br/><input id="last_name" type="text"/><br/>
          <button id="submit_button" onClick="return evaluateUserInput();">Submit</button>
        </form> 
        <p id="output">placeholder text until the `submit_button` is clicked</p>
    </body>
</html>