(JS) Disappear with a form Ubmit button after clicked

Asked

Viewed 159 times

0

Hello,

I wonder if there is a way to brush a button "Submit" of a form. Here is my situation:

I don’t have access to HTML as it is a Drupal application.

inserir a descrição da imagem aqui

I made a script that checks the browser’s localStorage and if the page has already been visited it disappears with the button. The problem is that the button would disappear forever.

var visita =  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 problem is that when the user returned for a year that had already been submitted the boot appeared even so.

So, 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 the name goes.

 $("#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();
        }
    });

1 answer

0

So, there 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 on the page some name

This does not work because Javascript will not keep its change when closing the browser and reopening.

You could store more information in Storage, such as the month/year the button was clicked, so when loading 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();
}

Browser other questions tagged

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