-5

This question came up in a project for creating a minimalist GUI running in browser for MongoDB.

How to reflect the current state of the database and update as appropriate? In other words, what are some ways of implementing CRUD with HTTP verbs and being able to have a dynamically updated page.

Currently, pug is used to generate the main page and with each creation, deletion and update, the page is regenerated and served back.

The server-side is running in node.js and express.

giannisl9
  • 151
  • 2
  • 11

1 Answers1

2

I think what you are trying to achieve is that you want a button which should submit the form on the click, and you have specifically said "using JavaScript", so let's go through that first. Firstly, lets make a form:

<form id="submit_this" action="action.php" method="post">
<input>........</input>
</form>

On the HTML Part, make a button first:

<button params="values" onClick="submit_form ();">

We are interested in the onClick methos of the Button, as this will execute the submit_form () function on click/tap.

Now, the code for submit_form ():

function submit_form () {
    document.getElementById("submit_this").submit();
}

This was specifically by using JavaScript, there are many other methods also, like, using JQuery:

$("#submit_this").submit ();

(P.S. - With JQuery, you can do a lot more than just submitting a form)

or Native HTML, In the button Markup, just keep it like this:

<button params="values" form="submit_this">

(P.S. - This is Specifically for HTML5)

Another Important Note: The params="values" means that, there are other parameters, like class, style, etc. etc, so don't just copy-paste the code, ***You might need to modify this according to your problem*

Aayush Sinha
  • 377
  • 4
  • 18
  • ok, but there is a need to redirect to the page when the operations on the database are complete, not when the button is hit – giannisl9 Dec 14 '16 at 06:57
  • So, for that, on the Script that you are executing, send a header type to change location (PHP), or redirect (Ruby/RoR), or any equiv. in the language you are working. – Aayush Sinha Dec 14 '16 at 07:00
  • can you be more specific? there is an express server running on the server-side – giannisl9 Dec 14 '16 at 07:12
  • I haven't worked much on node.js, but I feel this might help http://stackoverflow.com/questions/19035373/how-do-i-redirect-in-expressjs-while-passing-some-context – Aayush Sinha Dec 14 '16 at 07:17