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"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test button</title> <script src="./script.js"></script> </head> <body> <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=""> <h1></h1> </body> </html>
function greeting(a) { return "Hello " + a + ", nice to meet you" }
Advertisement
Answer
Do you want something like this?
function alpha(){ var str=document.getElementById('input1').value; str ===""? str = "Maria":null; console.log(str); alert(greeting(str)); } function greeting(a) { return "Hello " + a + ", nice to meet you" }
<input type="text" id="input1" /> <button onclick="alpha()" value="Maria">Click Me</button>