Javascript won’t output values from input box

Here’s a working version of your code.

  1. There’s no method getElementByName (but getElementsByName) – you should use document.getElementById() (Read about it here)
  2. You should use the value of the input element.
<!doctype html>

    align: center;

<script language="javascript" type="text/javascript">
    function output(){
        var name = document.getElementById('firstName').value;
        var Age= document.getElementById('age').value;
        document.getElementById('output').value = name+Age;

<h1><strong><em><center>Payment Details</center></em></strong> </h1>
<div class="formdiv">
<legend> Enter the following Info:</legend>
<br />
<label> Name </label>
<input type="text" id="firstName" placeholder="John" required="required"></input> 
<label>Age </label>
<input type="number" id="age" maxlength="2" required="required"></input>
        <button onClick="output()">Submit</button><br/>
<label for="output">Output</label>
<input type="textbox" id="output"></input>

Leave a Comment