arpit_s
arpit_s

Reputation: 19

Submit button load same page with button disabled

My code loads the same page after clicking the button, but I want the page loaded with the button disabled. Below is the java script code.

function disableSendVerifButton()
{
   $( '.sendVerificationButton' ).html( 'Verification Sent' );
   $( '.sendVerificationButton' ).attr( "disabled", true );

   // Change the button color
   $( '.sendVerificationButton' ).addClass( 'gray' );
}

But since the same page loads, the button does not gets disabled and loads with normal button. Please help.

Upvotes: 0

Views: 313

Answers (1)

David Hellsing
David Hellsing

Reputation: 108500

You could set a query string on the page on reload/submit, f.ex:

http://domain.com/?submitted

Then look for it in javascript:

if ( /^\?submitted/.test(window.location.search) ) {
    disableSendVerifButton();
}

Using a cookie: do somehting like this on submit/click before reload:

document.cookie='submitted=1;'

And then:

if ( /submitted\=1;/.test(document.cookie) ) {
    document.cookie='submitted=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'
    disableSendVerifButton();
}

Other options are localstorage or submitting through ajax.

Upvotes: 2

Related Questions