3

I am trying to call a Javascript function through a button I posted on my sharepoint page like so

<button type="button" onclick="myFunction(); return false;">Button</button>

But after I save the page and view the source again the code gets changed to this

<button type="button">Button</button>​​​

It totally removes the onClick event. Why is this? How can I fix it?

I have tried in the html editor, embedded code editor, and even tried to change it to input type=button all result in same behavior

3

The embedded source editor will strip the onclick event.

You will need to use a Content editor webpart or an HTML Form webpart.

https://social.msdn.microsoft.com/Forums/office/en-US/960cbc6f-ec7f-4641-88bd-0be3daa4668e/web-page-editor-not-accepting-onclick-attribute-in-button-tag?forum=appsforoffice

  • Hey yes this worked great! – Sudosu0 Jul 23 '18 at 13:06
0

I tested as your description, and could reproduce this issue.

To avoid this issue, I suggest you Content Editor web part or Script Editor Web part. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.