I would like to insert some JavaScript on a page, I want to create an hyperlink that could help me login into a page. So i use Embed Code

Embed Code

And I copy paste this:

<form id="form1" action="http://my.site.com/authentication/signin/" target="_blank" method="post">
    <input data-val="true" id="Username" name="Username" value="mybestusername" type="hidden">
    <input data-val="true" id="Password" name="Password" value="mybestpassword" type="hidden">
    <a href="#" onclick="document.forms['form1'].submit();">My Best HyperLink</a>

An hyperlink is created on the page but when I click on it it doesn't works! but if i save it on a html document it works. How to properly embed it?


When using 'Embed Code' it creates a Script editor webpart/control which itself resides in the asp.net <form>, so this won't work as you can't have a form in a form. The issue is that the javascript can't select your own form (not by getElementById, not by jQuery) so the submit()-function simply doesn't exist.

What you can try is to embed the working .html-file with your code using the page viewer webpart, as this is rendered through an <iframe> which will allow the code to execute.

  • I've found this hack that works link unfortunately I have this banner as I use <FORM>: <FORM> tags are not supported in the HTML specified in either the Content property or the Content Link property. You can remove the <FORM> tag, or use the Page Viewer Web Part, which supports the HTML <FORM> tag. The Content property can be modified in the Rich Text Editor or Source Editor. More about the Page Viewer Web Part – Francesco Mantovani Feb 2 '16 at 22:24
  • So... Is the page viewer webpart an option like I suggested? – meon Feb 3 '16 at 13:24
  • Yes if you embed the code from a .txt file, not from HTML – Francesco Mantovani Feb 3 '16 at 21:18

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.