HTML button event

Just starting out? Need help? Post your questions and find answers here.
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

HTML button event

Post 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 ??
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: HTML button event

Post 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;
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

Re: HTML button event

Post 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
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

Re: HTML button event

Post 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 ??
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

Re: HTML button event

Post 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
Post Reply