Saturday, 6 May 2017

calling a javascript function from html file

I making a simple twitter app using index.html and app js and server js the code for the app js using node the app js works fine but I can't call the function from inside the html I know the question has been asked many times I have read them and tried solutions but it still didn't work

var Twitter = require('twitter');

var client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});

function getUsername(username){
var params = {screen_name: username};

client.get('users/show', params, function(error, data, response) {
if(error){
    throw error;
  }
var followers_count = data.followers_count;
//console.log(followers_count);
});
  return followers_count + ""
}

and this is the html code

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Basic HTML Page</title>
<body>
    <!-- Link your JavaScript file -->
    <script src="app.js" type="text/javascript"></script>
    <h1>Enter the Twitter Username</h1>
    <input type="text" id="myText">
    <button onclick="myFunction()">Submit</button>
    <p id="followers_count"></p>
    <script>function myFunction(){
        var username = document.getElementById("myText").value;
        document.getElementById("followers_count").innerHTML = getUsername(username);
    }</script>
</body>



via Ahmed Al-Hadi

No comments:

Post a Comment