(JS) Drop with a submit form button after clicking

0

Hello,

I would like to know if you have a "submit" button on a form. Here is my situation:

I do not have access to HTML because it's a Drupal application.

ImadeascriptthatchecksthelocalStorageofthebrowserandifthepagehasalreadybeenvisiteditaddswiththebutton.Theproblemisthatthebuttondisappearsforever.

varvisita=localStorage.getItem('visited');if(visita=='true'){$("#edit-submit-teste").hide();
    }

    $("#views-exposed-form-teste-page").submit(function(e){
        localStorage.setItem('visited', 'true');
        $('option:selected', this).attr('name', "bananinha");
    });

To try to get around this, I wrote in the same script that every time the year or month changed, the button would come back from the ashes. The probe is that when the user returned for a year that had already been submitted the button appeared anyway.

Then, there in the code above, when the form was submitted I added a name to the option that was selected in the act. But I failed because every time I refresh the page or name some.

 $("#edit-field-de-value-value-year").change(function(){
        var attr = $('option:selected').attr('name');
        if (typeof attr !== typeof undefined && attr !== false) {
            $("#edit-submit-teste").hide();
        }else{
            $("#edit-submit-teste").show();
        }
    });
    
asked by anonymous 19.12.2018 / 14:33

1 answer

0
  

So, in the code above, when the form was submitted I added a   name for the option that was selected in the act. But I failed because   every time you refresh the page or name some

This does not work because JavaScript will not keep your change by closing the browser and reopening.

You could store more information in Storage, such as the month / year the button was clicked, so when you load the page, check the current month / year to see if it already exists in storage.

var visita =  localStorage.getItem('visited');
if(visita == 'FEB2017'){
  $("#edit-submit-teste").hide();
}
    
19.12.2018 / 15:10