Page 1 of 1

HTML button event

Posted: Wed Mar 22, 2023 5:54 pm
by William Van Hoecke
Hello,

I my program I use a webgadget() in which I load a htmlpage that contains a button like this

Code: Select all

<button id='button1' onclick='buttonclicked(this.id)'>Read All</button>
I my program I also have als an inline javascript function like

Code: Select all

! function buttonclicked(id)
! {
!   alert('id');
! }
When I click the 'Read All' button in the webgadget I would expect an alertbox reporting the button id, but ... nothing happens.
Debug console show
Uncaught ReferenceError: buttonclicked is not defined
What am I doing wrong ??

Re: HTML button event

Posted: Wed Mar 22, 2023 6:32 pm
by Peter
It may be that the function is in another scope and for this reason is not found.

Try the following:

Code: Select all

! function buttonclicked(id) {
!   alert(id);
! }
! window.buttonclicked = buttonclicked;

Re: HTML button event

Posted: Thu Mar 23, 2023 12:31 am
by William Van Hoecke
Thanks for the answer Peter,
Not sure what the window.buttonclicked = buttonclicked; is supposed to do and when it is called.
but ... it doesn't make any difference :(

Any other ideas

Re: HTML button event

Posted: Thu Mar 23, 2023 12:48 am
by William Van Hoecke
Peter,
definitly an out of scope, I've put the javascript function within the html form in webgadget and then the alertbox pops up.
Still my problem remains... how do I call function in my SB code ??

Re: HTML button event

Posted: Thu Mar 23, 2023 1:27 am
by William Van Hoecke
Peter,
I have solved the problem, I can now call SB function from within the webgadget.
the window. object you suggested can direct to the parent like this
<button id='button1' onclick='window.parent.f_clicked(this.id)'>Alles Lezen</button>

Thanks