A
A
Alexander2014-01-04 21:58:35
Node.js
Alexander, 2014-01-04 21:58:35

How to execute a function with a button in Node.js?

I want to ask for help. I am new to node.js.
For example, I made a web server as described here: www.nodebeginner.ru . Everything is working.
But there was a need, for example, in the start function to add a regular button that will launch another function.
This is about the same as it is written in the JS tutorial

<input type="button" onclick="countRabbits()" value="Считать кроликов!"/>

Tried various constructs like:
'<input id="b1" value="Нажми меня" click="testfun" type="button"/>'+

Does not work.
But if I just start the testfun() function in the body of the start function; then it starts up.
I describe the testfun() function in the same place as the start function (requestHandlers.js file)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuri Shikanov, 2014-01-04
@dizballanze

You are confusing something. What you need to do is normal javascript in the browser. Node.js has nothing to do with this, because it runs on the server, not the client.

A
Alexander, 2014-01-05
@livelisl

Hello.
No, I'm not confused. I also need the function to be executed on the server (roughly speaking, it calculates x + y). But the user could start these calculations with the push of a button. At the same time, without leaving the current page.

A
Artur Zayats, 2014-01-05
@zag2art

If you want without reloading the page, there are several ways:
1. Do it yourself using AJAX
2. Use some ready-made rpc module (RPC-remote procedure call, remote procedure call), for example https://github.com/substack/ dnode (in general, for node RPC, see modules here - https://nodejsmodules.org/tags/rpc )
3. Either manually using sockets (for example, socket.io)
4. Use for node instead of express.js some framework that was originally it can for example meteor.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question