Calling a method on OnClick using TypeScript
The call to IsMicrositeRequestValid
in the onclick
attribute requires that the function be part of the global namespace (window
). Further, I'm pretty sure you'll need to instantiate MicrositeRequest
object before the call to IsMicrositeRequestValid
work (because it relies on this
).
function validateRequest() { // declare a function in the global namespace
var mr = new MicrositeRequest();
return mr.IsMicrositeRequestValid();
}
<input type="submit" name="sumbit" value="Get" onclick="validateRequest()" />
is the quick & dirty way which should get it working.
You could also do this:
window.validateRequest = function () { // declare a function in the global namespace
var mr = new MicrositeRequest();
return mr.IsMicrositeRequestValid();
}
which I think is more readable.
Also, look into the Element.addEventListener
method. It allows much more flexibility.
var submit = document.getElementById('my-submit');
submit.addEventListener('click', function () {
var mr = new MicrositeRequest();
return mr.IsMicrositeRequestValid();
});
<input type="submit" id="my-submit" name="sumbit" value="Get" />