I had a node js application where I have my app.js and one html which gets displayed for the route /index.Now In my index file I had a button and text box and when I click button Iam trying to call a function.Where in that function I will have a variable with some text "Hello" which should be displayed in text box.I couldnt achieve this can some one help.
<html>
<body>
<div class="jumbotron" style="padding:40px;">
<h1>Hello!!!</h1>
<div>
<button type="submit" onclick="getData();">Call</button>
<input type="text">
</div>
</div>
</div>
</body>
</html>
app.js
app.get('/index',function(req,res){
res.sendFile(path.join(__dirname+'/index.html'));
});
function getData(){
console.log("Hello");
var text="Hello";
};
Right now Im getting reference error that getData is not defined.Can someone help over here.
getDatato your client side js file or just include it inscripttags in html.index.htmlfile is and include it<script src="fileName.js"></script>or you can write your js code inside<script></script>tags in html file which is not recommended. Also in your app.js file you need to specify where your static files are using `app.use(express.static(path.join(__dirname, 'PathHere')));publicand put your index.html and client side js file for examplemain.js, and then in your app.js file add thisapp.use(express.static(path.join(__dirname, 'public')));