Skip to content

Making a Button that outputs a greeting

I’m kinda new to programming and need help with integrating javascript and html. I am trying to make an html page that has a name input section and a submit button to give a greeting from the function in a javascript file. I’ve tried using the form and input tags and was wondering how i output to the html page.

Thank you in advance.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test button</title>
    <script src="./script.js"></script>
    <form name="testbutton" action="" method="GET">Enter your name</form>
    <input type="text" name="inputbox" value="">
    <input type="button" name="button"  value="click" onclick="greetings(this.form)" id="">
function greeting(a) {
    return "Hello " + a + ", nice to meet you"


Do you want something like this?

function alpha(){
  var str=document.getElementById('input1').value;
  str ===""? str = "Maria":null;
function greeting(a) {
    return "Hello " + a + ", nice to meet you"
<input type="text" id="input1" />
<button onclick="alpha()" value="Maria">Click Me</button>