Jump to content

Passing Variable to Javascript


Wajeed

Recommended Posts

Newbie to unigui and javascript,

I am trying to pass variable from a unigui form to javascript.I tried two methods as discussed in forum

First method

on Mainform.oncreate
 Self.WebForm.JSInterface.JSAssign('myvar', [2356]);

on same form button1 clientevents(ExtEvents) , I tried to access the variable

function click(sender, e, eOpts)
{
  var n1 = MainForm.windows.myvar;
  alert(n1);
}

nothing happens.

-----------------

Second method
on Mainform button click

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
UniApplication.UniSession.AddJS('var myVar = 1');
end;

clientside(Extevents)
function click(sender, e, eOpts)
{
  var n1 = uniVars.myVar ;
  alert(n1);
}

i get undefined alert message at runtime when i click the button.

 

 

image.png

Link to comment
Share on other sites

28 minutes ago, Wajeed said:

First method

on Mainform.oncreate
 Self.WebForm.JSInterface.JSAssign('myvar', [2356]);

on same form button1 clientevents(ExtEvents) , I tried to access the variable

function click(sender, e, eOpts)
{
  var n1 = MainForm.windows.myvar;
  alert(n1);
}

nothing happens.

 

29 minutes ago, Wajeed said:

  var n1 = MainForm.windows.myvar;

Correct - var n1 = MainForm.window.myvar;

  • Like 1
Link to comment
Share on other sites

Thanks, works perfect.

Now, i cannot do the same in Uniframe.

 Self.WebForm.JSInterface.JSAssign('myvar', [2356]);  gives error undeclared indentifier webform.

may be i am missing some files in uses class. please help

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...