program test5;
{$mode objfpc}
uses
JS, Classes, SysUtils, Web;
Type
{ TDemoform }
TDemoform = class
Panel, Panel2 : TJSElement;
Item1 : TJSElement;
Item2 : TJSElement;
Item3 : TJSElement;
Lblindex : TJSElement;
Button : TJSElement;
teller : integer;
constructor create;
procedure CreateElements;
private
procedure CreateButton(aPanel, aItem: TJSElement; const aID: string;
const aValue: string);
procedure CreateEdit(aPanel, aItem: TJSElement; const aID: string; const aValue: string = '');
procedure CreateLabel(aPanel: TJSElement; const aCaption: string); overload;
procedure CreateLabel(aPanel, aItem : TJSElement; const aCaption : string); overload;
public
function ButtonClick(Event: TJSMouseEvent): boolean;
end;
{ TDemoform }
constructor TDemoform.create;
begin
teller := 1;
CreateElements;
end;
procedure TDemoform.CreateLabel(aPanel : TJSElement; const aCaption : string);
var MyLabel : TJSElement;
begin
MyLabel := document.createElement('label');
MyLabel.innerText:=aCaption;
aPanel.appendChild(MyLabel)
end;
procedure TDemoform.CreateEdit(aPanel, aItem : TJSElement; const aID : string; const aValue : string);
begin
aItem :=document.createElement('input');
aItem['id'] := aID;
aItem['type'] := 'text';
if aValue > '' then
aItem.innerText := aValue;
aPanel.appendChild(aItem);
end;
procedure TDemoform.CreateButton(aPanel, aItem : TJSElement; const aID : string; const aValue : string);
begin
aItem :=document.createElement('input');
aItem['id'] := aID;
aItem['type'] := 'button';
if aValue > '' then
aItem['value'] := aValue;
aPanel.appendChild(aItem);
end;
procedure TDemoform.CreateLabel(aPanel, aItem : TJSElement; const aCaption : string);
begin
aItem := document.createElement('label');
aItem.innerText:=aCaption;
aItem['id'] := 'counter';
aPanel.appendChild(aItem);
end;
procedure TDemoform.CreateElements;
begin
Panel :=document.createElement('div');
// attrs are default array property...
Panel['class']:='panel panel-default';
document.body.appendChild(panel);
CreateLabel(panel,'item1');
CreateEdit(panel, item1,'tekst1');
CreateLabel(panel,'item2');
CreateEdit(panel, item2,'tekst2');
CreateLabel(panel,'item3');
CreateEdit(panel, item3,'tekst3');
Panel2 :=document.createElement('div');
Panel2['id'] := 'mycounter';
Panel.appendChild(panel2);
CreateLabel(Panel2,Lblindex,inttostr(teller));
CreateButton(panel, button,'btndoorgaan','doorgaan');
TJSHTMLElement(button).onclick:=@ButtonClick;
end;
function TDemoForm.ButtonClick(Event: TJSMouseEvent): boolean;
var MyLabel : TJSHTMLElement;
begin
teller := teller + 1;
MyLabel := TJSHTMLElement(document.getElementById('counter'));
MyLabel.innerText := IntToStr(teller);
result := true;
end;
begin
TDemoForm.create
end.