I have a small form and some javascript that I am trying to add to a Sharepoint Page Layout. The script works great outside of Sharepoint.

However in the SharePoint Page Layout when I used

<form name="myform">

this tag was always removed from the DOM as I understand now form tags are not supported. I found a suggestion to instead use something like

<weatherform name="weatherform">

This helped in that it is no longer being stripped from the page. My javascript though, which I have changed to use

var word = document.weatherform.site.selectedIndex;

is throwing a Javascript error of TypeError: document.weatherform is undefined

Any suggestions?



I think the reason that this is allowed in the first place is that the element <weatherform> does not have any meaning either to SP designer nor to the HTML parser. Hence, you are able to add the tag without nesting forms; the element's type is undefined, do you cannot .

What you may want to do is give your select input (I'm making an assumption as to the input type here) an id and then reference it by using the getElementById function. So, if you give it an ID of "site":

<select id="site" name="site" onChange="someFunction();">

and then within someFunction(), get the element by id:

var word = document.getElementById("site").selectedIndex;

you should get the correct value assigned to your variable. And, unless you are sending the form input to a script for processing, not having a specific form container for your input elements should not be a problem.

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.