Skip to content
Loading
Signaturepad is not working clear button on the form
  • Tuhin Paul

    Consider adding error handling to the AJAX call to handle situations where the signature data cannot be saved to the server.

  • Tuhin Paul

    An improved version 

    // HTML code
    
    
    // JavaScript code /** Allows a user to sign using the SignaturePad library. */ $(document).ready(function() { // Initialize signature pad var canvas = document.getElementById('signatureCanvas'); var signaturePad = new SignaturePad(canvas); // Handle clear button click $('#clearButton').click(function(){ console.log('Clear button clicked!'); signaturePad.clear(); alert("Test1"); }); // Handle save button click $('#saveButton').click(function(){ var signatureDataURL = signaturePad.toDataURL(); alert("test2"); // Send signature to the server $.ajax({ type: 'POST', url: 'save_signature.php', data: { signature: signatureDataURL } }) .done(function(response){ console.log(response); }) .fail(function(xhr, status, error) { console.error(xhr, status, error); alert("An error occurred while saving the signature."); }); }); });