Forum > Pas2JS
Why this.edtEmail is undefined?
cappe:
Why with this code:
{$mode objfpc}
uses
browserapp, JS, Classes, SysUtils, Web, fpjson, fpjsonjs, fprpccodegen;
type
{ TMyApplication }
TMyApplication = class(TBrowserApplication)
edtEmail: TJSHTMLInputElement;
edtPassword : TJSHTMLInputElement;
btnLogin : TJSHTMLButtonElement;
procedure doRun; override;
private
procedure BindElements;
procedure doLoginClick(aEvent: TJSEvent);
procedure doServerLogin(const aUser, aPassword: String);
end;
procedure TMyApplication.doRun;
begin
BindElements;
btnLogin.AddEventListener('click',@DoLoginCLick);
Terminate;
end;
procedure TMyApplication.BindElements;
begin
edtEmail:=TJSHTMLInputElement(GetHTMLElement('edtEmaill'));
edtPassword:=TJSHTMLInputElement(GetHTMLElement('edtPassword'));
btnLogin:=TJSHTMLButtonElement(GetHTMLElement('btnLogin'));
end;
procedure TMyApplication.doLoginClick(aEvent: TJSEvent);
begin
window.alert(edtEmail.value);
DoServerLogin(edtEmail.value,edtPassword.value);
end;
procedure TMyApplication.doServerLogin(const aUser, aPassword: String);
begin
window.alert('Logging in with user: '+aUser);
// to be implemented.
end;
Why does doLoginClick give me the following error? A seems correct.
Uncaught TypeError: this.edtEmail is undefined
doLoginClick client.lpr:50
cb rtl.js:256
DoRun client.lpr:29
Run custapp.pas:206
$main client.lpr:66
run rtl.js:141
lainz:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---'edtEmaill'
It has double L in the end
cappe:
--- Quote from: lainz on November 07, 2022, 04:04:21 pm ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---'edtEmaill'
It has double L in the end
--- End quote ---
That's not the problem, I have attached the project, I try with pas2js 2.2.0 I can't get it to work.
The strange thing is that inside the BindElements works, edtEmail works correctly, while in doLoginClick it gives me "Uncaught TypeError: this.edtEmail is undefined"
440bx:
@cappe,
your opening post would be much easier to read if you used code tags to format the code. ;)
PierceNg:
--- Quote from: cappe on November 07, 2022, 04:09:44 pm ---That's not the problem, I have attached the project, I try with pas2js 2.2.0 I can't get it to work.
The strange thing is that inside the BindElements works, edtEmail works correctly, while in doLoginClick it gives me "Uncaught TypeError: this.edtEmail is undefined"
--- End quote ---
"It works on my computer"TM with pas2js 2.2.1. The login box is displayed, the alert modal pops up, and browser console shows no relevant error.
Navigation
[0] Message Index
[#] Next page