With Javascript is it possible to automatically execute a function on another part of the file?

Asked

Viewed 24 times

0

I have two separate pages:

  • The first contains a form with two fields input of the kind date, among other information.
  • The second page receives a data from the form information that I mentioned before, but not the dates.

The first sends this data to the Mongo DB Atlas. The second shows one of these data, which is a button title. On these two pages I’m using the Node.js also.

I have a function that checks whether the current date is longer than the final date passed by the user. If yes, when this condition is met I would like that button, which in turn is on the second page, ie in a file html different, would be automatically disabled.

It seems advanced to me and I do not know if it is possible to do such a thing, because it involves two files html different, where one possesses the input of the kind date - and consequently it is in this file that I must include the script which does this check - and another, where is the button I need to have disabled when this condition - if the current date is longer than the final date - is true.

In short, I need to make this function written in a separate file perform an automatic action in another file html different.

I asked a question here and a friend of Sopt helped me to arrange this function, but it is only a function and still does not solve this new challenge I described above. My biggest challenge now is to exchange this function between two files.

  • Hello, is the information saved in the database? if yes, in the second html file it is not possible to query the database and check if the condition to display/disable the button is true?

  • @Jhonatadesouza Yes, the information is in a database. I haven’t implemented the function yet because I don’t know how to run it in the second file. In case I suppose it should come in the first file, where are the date fields. I did a search and I think the import and export of javascript can help me, I still do not know how but I will test.

1 answer

0

Only with the frontend, you can pass the dates to the other file using localStorage, in timestamp format. Example:

In the first file, you save in localStorage:

var minhaData = new Date();
localStorage.setItem( 'minhaData', minhaData.getTime() );

In the second, you read the date with:

var minhaData = new Date( localStorage.getItem('minhaData') );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.