3

In app.js I have hard-coded 3 keywords:

var a = 'family';
var b ='friends';
var c ='teacher';

and saved them in an array called 'List'

var List = [a, b, c];

Now I passed this List in track (Twitter API)

twit.stream('statuses/filter', { track: List }, function(stream) {
    stream.on('data', function (data) {
        // code
    });
}); 

Now, I want to accept the user's keywords, so in index.html I am providing 3 textboxes (i.e. <input type="text">)

When the user enters the first keyword in textbox 1 it should be assigned to var a of app.js, when the 2nd keyword is inserted it should be assigned to var b, and so on.

<html>
<head>
</head>
<body>
    <form>
        Key 1<input id="Key_1" class="" name="" type="text" placeholder="First key" required /><br><br>
        Key 2<input id="Key_2" class="" name="" type="text" placeholder="Second key" required /><br><br>
        Key 3<input id="Key_3" class="" name="" type="text" placeholder="Third key" required /><br><br>

        <button type="submit" form="form1" value="Submit">Submit</button>
    </form>
</body>
</html>

How can I do this?

1 Answer 1

3

You could do something similar from this question: How to get GET (query string) variables in Express.js on Node.js?

So when submitting the form, you could get the query parameters. But first, you'd need to give each input a name, lets say a, b and c:

<html>
<head>
</head>
<body>
<form method="post">

Key 1<input id="Key_1" class="" name="a" type="text" placeholder="First key" required /><br><br>
Key 2<input id="Key_2" class="" name="b" type="text" placeholder="Second key" required /><br><br>
Key 3<input id="Key_3" class="" name="c" type="text" placeholder="Third key" required /><br><br>

<button type="submit" form="form1" value="Submit">Submit</button>
</form>
</body>
</html>

Then you would need to make your HTML form post the data somewhere in your Node app and get the request values using this:

app.post('/post', function(req, res){
  a = req.query.a;
  b = req.query.b;
  c = req.query.c;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.