Learn value returned by an onsubmit form in HTML5 CanvasInput

1

First of all greetings to all and to say that I am very new, any correction is welcome, both the question I am asking and the use of this website ...

I was trying to get the method onsubmit() of the library "CanvasInput" of HTML to return the value I write in the form ...

The value that returns to me is the following:

function 

Javascript Code:

var input = new CanvasInput({
  canvas: document.getElementById('canvas'),
  value: '',
  onsubmit: function() {alert(this.value);},
});
    
asked by Alberto García Olmedo 12.06.2016 в 19:27
source

2 answers

1

Effectively when you call this you are referencing the function and not the new instance of CanvasInput, since the onsubmit function will be called after creating the object, you can simply call input.value .

This should work:

var input = new CanvasInput({
  canvas: document.getElementById('canvas'),
  value: '',
  onsubmit: function() {
    alert(input.value);
  },
});
    
answered by 13.06.2016 в 03:37
1

As I can see in the source code of CanvasInput ( Line 880 ), the handler of the event receives a second parameter that is effectively the CanvasInput.

So you can add this parameter to the callback function to get the value.

var input = new CanvasInput({
  canvas: document.getElementById('canvas'),
  value: '',
  // aquí agregar y usar los parámetros 
  onsubmit: function(e, canvasInput) { alert(canvasInput.value); },
});
    
answered by 13.06.2016 в 05:30