Page 1 of 1

Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 9:32 am
by lummis
I am attempting to run two JavaScript events when using onclick. The events are "mySqlDelete()" and "window.location.href='http://www.mydomain.com' ".

I have tried with using " mySqlDelete(); window.location.href='http://www.mydomain.com' " but the second event is not actioned although both parts work independently if I remove one event.

Any suggestions please.

Brian

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 9:49 am
by Pablo
This should work because this is standard HTML functionality.
Maybe you have made a type error?
You can use the browser's debugger (F12) to see what is wrong.

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 10:04 am
by lummis
The browsers debugger is not showing any errors and I am sure that I had it working a couple of months ago when testing. I can't think of any changes that I have made that would affect things. Is there a workaround which would achieve what I am trying to do i.e. moving to another page after the database deletion?

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 10:10 am
by Pablo
If you need further assistance then please share a demo project so I can see what you have done.

Read this carefully before sharing:
http://www.wysiwygwebbuilder.com/forum/ ... 10&t=82134

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 10:55 am
by lummis
As requested here is the wbs file stripped down.

https://www.stowaways.org/StowawaysDeletePage.wbs

The project does include the SQL connector extension in the opening page as it is an integral part.

The purpose of the page is twofold. First to delete an entry in a database and secondly to mail an advice to the sender and the webmaster. The second part is achieved by redirecting to the page "delete_entry_mailing", which contains the standard form mailer, and the button on that page is automatically clicked via a script.

As previously stated , the two functions for the onclick event in the first page work when used separately but do not redirect to the second page when combined.

Have I over-complicated the process or is there another way?

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 11:14 am
by Pablo
The reason why this does not work is because mySqlDelete() reloads the page, so in this case all code after the function is ignored by the browser.

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 11:26 am
by lummis
If that is the case, is there a way I could arrange the redirect after the page has been reloaded?

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 11:31 am
by Pablo
There is no standard solution for this becuase you will have to keep track of what the last action was (with cookies or webstorage) before the page gets reloaded. This can only be done with custom code.

Re: Can I have two JavaScript onclick events in one input type button tag?

Posted: Thu Jun 03, 2021 11:38 am
by lummis
Thanks Pablo, at least I know why the onclick function was not working. I will try to think of another way or just abandon the emails about the deletion.