[SOLVED] Submit Form and How To Reload Page


#1

I am working on my first electron application (a simple password encryption tool) while learning to use the new JS technologies.
Background:
I have a form that I am filling in and it is submitted. I have setup an event listener for the form submit.
I know the event listener works because I can write a message to the console.

Here is the Question - How do i re-display the same form/page with a result (ie a reply message)?

here is my event listener from the the js file

formSubmit.addEventListener('submit', function(evt){
     console.log("in event listener");
    var textValue=   document.getElementById('rawText').value;
    console.log("RawText is: " + textValue);
   //display the same form with result
})

#2

Hi,

I am not sure that I understand your question correctly, I am assuming the following is your requirements

You have a form
You fill all the details,then submit
the server or function will give you success/failure message
You need to display the server response below the form

is it right ?
Are you using ajax to submit a form to server or you submit to some other function?

Once you receive a reply from server/function insert that message in html of the same form.

If not please explain your exact usecase


#3

myfrndjk,
Yes your description is correct.

You have a form
You fill all the details,then submit
the server or function will give you success/failure message
You need to display the server response below the form

For the record, I do not want to use Ajax to handle the submit and response.
And as a side note - since this is an Electron application and is contained to the desktop (no internet, no db) , there is no ‘Server’ per se; minor point.


#4

In your form html add a tag for this message

<div class="updatefromserver">
    <p></p>
</div>

once you get reply from function

var server_message =‘data submitted successfully’
$(".updatefromserver").find('p').append(server_message);

Use css properties to move that ‘updatefromserver’ class to desired location.

If your requirements are different, paste your code and mention what you have tried and where you are getting stuck.So that we can direct you accordingly


#5

Actually, that is not what I am asking about. I understand html​. I am
asking about the back end code… see the function snippet in the original
post.


#6

I have been able to figure it out.
Since the form is being posted, it wants to reload except, what you put back in the page will disappear.
What is required it to add evt.preventDefault()
This will stop the page from reloading, fresh.